Add 20 percent to each price and join the results with commas.
Acceptance criteria
- 1.#out should show 120,240.
JavaScript Tutorial · JavaScript Functions
These 10 tasks go with the JavaScript Higher Order Functions chapter. 5 of them ask you to build something small from scratch; 5 give you code that is already broken and ask you to work out why. Set aside about 90 minutes for the whole set, though you can do them in any order.
Nothing here is marked by a person. When you press Submit, the editor checks your code against the points listed under each task and tells you straight away what passed and what didn't (you need a free account to submit). If you get stuck, there are hints, and a worked solution once you've had a go. The first 2 tasks are free; the rest are part of the practice plan.
If it's been a while since you read the chapter, here is how it starts: “A JavaScript higher order function is a function that takes a function as an argument or returns one.” .
1.Transform with mapexercise · easy · 10 min
Add 20 percent to each price and join the results with commas.
Passes when: #out should show 120,240.
2.Keep some with filterexercise · easy · 10 min · practice plan
Keep only numbers above 4 and join them with commas.
Passes when: #out should show 8,12,5.
3.Total with reduceexercise · easy · 10 min · practice plan
Add 1, 2, 3 and 4 together using reduce.
Passes when: #out should show 10.
4.Return a functionexercise · easy · 10 min · practice plan
Write a function that builds a multiplier, then triple 15.
Passes when: #out should show 45.
5.Chain them togetherexercise · medium · 10 min · practice plan
Keep the even numbers from 1 to 6, multiply each by 10, and add them up.
Passes when: #out should show 120.
6.Fix forEach used instead of mapbug fix · easy · 8 min
forEach returns nothing, so there is no new array.
Passes when: #out should show 120,240.
7.Fix the filter that returns nothingbug fix · easy · 8 min · practice plan
The callback has braces but no return, so nothing is kept.
Passes when: #out should show 8,12,5.
8.Fix the missing starting valuebug fix · easy · 8 min · practice plan
Without a starting value the first item is used as the total.
Passes when: #out should show 20.
9.Fix the function called instead of returnedbug fix · easy · 8 min · practice plan
The outer function returns a number, not a function.
Passes when: #out should show 45.
10.Fix the wrong chain orderbug fix · easy · 8 min · practice plan
Multiplying before filtering changes which numbers are kept.
Passes when: #out should show 120.
Between them these tasks cover map, filter, reduce, Returning functions and Chaining.
Looking for a different chapter? See every practice set, or switch to the interview theory questions.