Rideshare
Home
Part 1
Write JavaScript code to process the provided rideshare variable to answer the questions below.
Log each of the answers to the console.
- Display a human-friendly message to denote the driver's first name (i.e. "Your driver is Danny").
- Display the license plate number (i.e. "ABC-1234").
- Display the number of stops this trip makes (i.e. 3).
- Display the destination of the first stop (i.e. "Logan Circle").
- Display the destination of the last stop (i.e. "Washington Circle"). NOTE: your solution should work regardless of how many stops there are (i.e. should reference the last item dynamically, not assume the third stop is necessarily the last).
- Loop through each of the stops and display that stop's passenger name, one at a time (i.e. "Vishal", then "Clara", then "Lee", each on a separate line).
- Use a mapping operation to arrive at an array of just the numeric fare values, store them in a variable called
fares, and display them.
- Calculate and display the total fare for the entire trip, which is equal to the sum of all the fares for all passengers.
Format the total fare as USD, with a dollar sign and rounded to two decimal places.
HINT: use an accumulator approach in conjunction with Question G,
or use the
d3.sum() function
from the d3-array library.
Part 2
Write JavaScript code to process the provided rideshare variable to answer the questions below.
Display the answers on the page in the designated places.
- Display the driver's first name. Use the designated
span element.
- Display the vehicle's make, model, and license plate number. Use the designated
span element.
- Loop through each of the stops and display that stop's passenger name, one at a time (i.e. "Vishal", then "Clara", then "Lee", each in a separate list item).
Use the designated
ol element.
Driver: TODO
Vehicle: TODO
Passengers: