Chapter practice task
Task: Build a small price calculator for your services
- Store your services as an array of objects with a name and a price.
- Write a function that takes a list of chosen services and returns the total.
- Use
filterto get only the chosen services andreduce(or a loop) to add the prices. - Show the total on the page, formatted with a currency sign.
- Add a 10% discount when the total is over a set amount.
By the end of this chapter
- You can write functions with parameters and return values, including arrow functions
- You can use the most common array methods: push, map, filter, find, includes and reduce
- You can create and update objects, and work with arrays of objects
Quick answers for this chapter
What’s the difference between a function and a method?
A method is just a function stored inside an object, like skills.push().
Arrays or objects?
Arrays for ordered lists of similar things; objects for one thing with named properties.
What’s JSON?
A text format that looks like JavaScript objects and arrays, used to send data between servers and browsers.