People List EJS: Individual Exercises
Update the People List application by completing the following exercises.
Updating the Person Page Styles
- In the person.ejs file, set the font to "Chiller" if the person is dead
- Set the font to "Arial" if the person is alive
- Run the program, and verify that the fonts reflect the alive status of each person!
Adding a Wrench
If the person is an engineer of any kind, they should have a wrench icon under their occupation.
- Open the person.ejs file
- Make a new line under the
<p>that has the person's occupation - Create an
<%= if () { %> <%= } %>structure - For the
ifcondition, check if the person'sjobcontains the text'Engineer' - In the body of the
if, place the wrench emoji in ap:<p>🔧</p> - Run the program, and verify that "Engineer" people have a wrench on their pages!
Moving the Avatar to the Homepage
- Remove the avatar
<img>from the/personpage - On the homepage, update the person list so each
lihas an image before the name:<li> <img src="" /> <a href=""><!-- etc --></a> </li> - Update the image so that it points to the given person's avatar
Adding Pagination
- In the app.js file, in the
personPagefunction, find theresponse.rendercall - Update the object passed to
response.renderso that it has anidxproperty- The value should be the
indexfrom the query parameter
- The value should be the
- In the person.ejs file, at the bottom, add an
athat links to the previous page- The
hrefshould be/person?index=with the previous index (<%= idx-1 %>)
- The
- Under the "previous page" link, add another
athat links to the next page (<%= idx+1 %>)
BONUS - Dynamic Paging
- Use EJS to create an
ifstatement that shows the "previous page" link only if the currentidxis greater than0 - Use EJS to create an
ifstatement that shows the "next page" link only if the currentidxis less than24
Alphabetic List Sorting
Note: This challenge is very challenging and provides very little guidance.
- In the app.js file, in the
homePagefunction, add code to handle asortquery parameter - If the
sortquery parameter istrue, send over the array of people sorted in alphabetical order - If the
sortquery parameter is anything else, send the normal array - Add links on the
/homepage to sort/unsort the list of people
Challenge - Making Sorted Pagination Work
Update the /home page so that, if clicking a person link while in sort mode, the pagination on the /person page will respect the alphabetic order.
CHALLENGE - Editable Occupations
Note: This challenge is very challenging.
Update the app so that the user can edit a person's occupation on the /person page.
- On the server, create a new POST request handler that takes a person's name and their new occupation, and updates the
peopleJsonobject - Create an HTML form on the
/personpage to get the new name from the user