Skip to main content

JavaScript Arrays — exercises and bug fixes

5 hands-on exercises and 5 find-the-bug challenges for the JavaScript Arrays 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. 1

    Create an array

    easy10 min

    Create an array of three fruit names and show how many it holds.

  2. 2

    Show an empty array length

    easy10 min

    Create an empty array and show its length.

  3. 3

    Store mixed types

    easy10 min

    Create an array holding a string, a number and a boolean, then show the type of the middle element.

  4. 4

    Count a nested row

    medium10 min

    Create a grid of two rows with three values each and show the length of the first row.

  5. 5

    Grow a const array

    easy10 min

    Push a value onto an array declared with const and show the new length.

Find the bug(5)

  1. 1

    Fix the missing commas

    easy8 min

    The array was written without separators, so it holds one value instead of three.

  2. 2

    Fix the wrong brackets

    easy8 min

    Curly braces make an object, not an array, so there is no length.

  3. 3

    Fix length called as a function

    easy8 min

    length is a property, not a method.

  4. 4

    Fix the flat grid

    easy8 min

    The grid should hold rows, but every value was put in one list.

  5. 5

    Fix the array that was replaced

    easy8 min

    Building a new array loses the earlier values instead of adding to them.

Ready to write the code?

The editor, the automatic checks and the worked solutions open up with an account.

Open the workspace