JavaScript Array Access — exercises and bug fixes
5 hands-on exercises and 5 find-the-bug challenges for the JavaScript Array Access 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
Read the first element
easy10 minShow the first element of an array of fruit names.
- 2
Read the last element
easy10 minShow the last element using the array length.
- 3
Use at with a negative index
easy10 minShow the second-to-last element using at().
- 4
Replace an element
easy10 minReplace the middle element with Cherry and show the whole list joined by commas.
- 5
Read from a nested array
medium10 minShow the value in the second row, first column of a grid.
Find the bug(5)
- 1
Fix the off-by-one first element
easy8 minCounting starts at 0, not 1.
- 2
Fix the last element past the end
easy8 minUsing length as an index reads one place too far.
- 3
Fix the index in quotes
easy8 minA string is treated as a property name, not a position.
- 4
Fix at used with a positive one
easy8 minat(1) is the second element, not the last.
- 5
Fix the single bracket on a grid
easy8 minOne pair of brackets gives a whole row, not a value.
Ready to write the code?
The editor, the automatic checks and the worked solutions open up with an account.
Open the workspace