JavaScript for of Loop — exercises and bug fixes
5 hands-on exercises and 5 find-the-bug challenges for the JavaScript for of Loop lesson. Every one is checked automatically in the browser — write the code, run it, and the tests tell you what still fails.
Exercises(5)
- 1
Add up an array
easy10 minAdd every number in the array together and show the total.
- 2
Join the values
easy10 minJoin the fruit names together with a comma.
- 3
Count the letters
easy10 minCount how many characters are in the text, ignoring spaces.
- 4
Use the index with entries
easy10 minShow each fruit with its index, joined by commas.
- 5
Find the largest number
medium10 minFind the largest number in the array and show it.
Find the bug(5)
- 1
Fix for in used instead of for of
easy8 minfor in gives the index, so the totals are wrong.
- 2
Fix the index treated as a value
easy8 minThis joins the indexes instead of the fruit names.
- 3
Fix the missing entries call
easy8 minWithout entries there is no index to unpack.
- 4
Fix the comparison that never updates
easy8 minThe comparison is the wrong way round, so the smallest wins.
- 5
Fix the break that should be continue
easy8 minThe loop stops at the first space instead of skipping it.
Ready to write the code?
The editor, the automatic checks and the worked solutions open up with an account.
Open the workspace