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
if
condition, check if the person'sjob
contains 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/person
page - On the homepage, update the person list so each
li
has 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
personPage
function, find theresponse.render
call - Update the object passed to
response.render
so that it has anidx
property- The value should be the
index
from the query parameter
- The value should be the
- In the person.ejs file, at the bottom, add an
a
that links to the previous page- The
href
should be/person?index=
with the previous index (<%= idx-1 %>
)
- The
- Under the "previous page" link, add another
a
that links to the next page (<%= idx+1 %>
)
BONUS - Dynamic Paging
- Use EJS to create an
if
statement that shows the "previous page" link only if the currentidx
is greater than0
- Use EJS to create an
if
statement that shows the "next page" link only if the currentidx
is less than24
Alphabetic List Sorting
Note: This challenge is very challenging and provides very little guidance.
- In the app.js file, in the
homePage
function, add code to handle asort
query parameter - If the
sort
query parameter istrue
, send over the array of people sorted in alphabetical order - If the
sort
query parameter is anything else, send the normal array - Add links on the
/home
page 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
peopleJson
object - Create an HTML form on the
/person
page to get the new name from the user