Skip to content

Instantly share code, notes, and snippets.

@ryanorsinger
Last active July 12, 2019 15:30
Show Gist options
  • Save ryanorsinger/6aa216d159f526441a47fdf480e95737 to your computer and use it in GitHub Desktop.
Save ryanorsinger/6aa216d159f526441a47fdf480e95737 to your computer and use it in GitHub Desktop.
Working with Arrays of Objects in JS
let cart = [
{
"name": "apple",
"price": 1.25,
"quantity": 5
},
{
"name": "kiwi",
"price": 3.99,
"quantity": 7
},
{
"name": "orange",
"price": 1.50,
"quantity": 8
},
]
// How would we determine how many types of items are in the cart? What if there are more than we can reasonably, manually count?
// Write the code necessary to access the number of apples
// Write the code necessary to determine how much we spent on kiwis, in total
// Write the code to sum up the quantity of all items in the cart
// Write the code necessary to update the cost of each fruit to be 30% more.
// Write the code necessary to determine the average cost per item. Add price*quantity for each item together then divide by the total number.
// Write the code necessary to convert each item's price property into a string with a dollar sign like "$1.50"
// Write the code necessary to capitalize the first letter of each item's name property.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment