Refer to the class notes!
-
Fork and clone this directory, then create a new directory inside it.
-
Move into the new directory you created, and make a
server.js
file. -
Inside the directory you created, initialize a node project. Remember to use
server.js
as the main starting point for your app.
If you're really stuck on this step, compare your directory structure to what is inside the setup-check
directory.
Refer to the class notes!
Create a root route that responds by sending an index.html
file from a new views
directory.
If you're really stuck on this step, compare all your files and code to what is inside the setup-check
directory.
-
Build a route that allows a user to guess a number through query parameters (for example,
/pickanumber?number=10
). The route should check the user's number against some target number variable stored in the server code. When the user navigates to this route in the browser, the server should respond with either "Too High", "Too Low" or "Nailed it!" For example, if the target number is 7, then a request to/pickanumber?number=10
should trigger a response of'Too High'
. -
Add the form below to your
index.html
, and use AJAX inapp.js
to submit it to the route you just created. Bonus: if the request is succesful, display the server's response on the page.
<form id="guess-number-form">
<input id="guess-num" name="number" placeholder="guess a number" type="text" />
<input type="submit" />
</form>
-
Build another route at
/pick-a-number
that allows a user to submit a form with a new target number for the guessing game. -
Add the form structure below to your HTML, and use AJAX in
app.js
to submit it to the route you just created.
<form id="target-number-form">
<input id="new-num" name="number" placeholder="enter new target number" type="text" />
<input type="submit" />
</form>
-
Create an
artworks
array in the server code. Each artwork will be an object with atitle
key, anartist
key, and adescription
key. -
Write a route that returns a list of all of the artworks as JSON.
-
Write a route that allows you to add a new artwork to the list of artworks. For this particular app, we'll have this route respond with JSON for all the artworks.
-
Create a new HTML view called
art-gallery.html
. Add a route at/art-gallery
to display this view. Add a form to this view that collects the information you need to add a new artwork. -
Create a new client-side JavaScript file called
gallery.js
, link it to yourart-gallery.html
, and write an AJAX call to submit the new artwork form to the correct route with its data. If the request is successful, log the response to the console in the browser. -
Stretch Challenge: Update the client-side JavaScript so that once an artwork is added successfully on the server, the artwork information is displayed on the page. Write a function that templates the data from an artwork into an HTML string that jQuery can add to the page.