Skip to the content

Creating and indexing

JavaScript · Unit 5: Arrays

An array keeps several values in order. You write it inside brackets [], with commas between the values.

When you print it, the console shows the text in single quotes: it is the same thing.

const fruits = ["fig", "plum"];
console.log(fruits);

Prints

[ 'fig', 'plum' ]

The rest of the explanation is in the lesson, which is part of the full plan.

Exercises in this lesson

You do them in the app, which checks them on the spot and explains why.

  1. 1. Multiple choice

    Which of these lines creates an array with three numbers?

  2. 2. Predict the output

    What does this code print?

  3. 3. Complete the code

    Complete it to print "Ava", the third one in line.

  4. 4. Complete the code

    Complete it to print how many days there are.

  5. 5. Predict the output

    What does this code print?

  6. 6. Predict the output

    What does this code print?

  7. 7. Find the bug

    This program should print the last person in line. Which line has the error?

  8. 8. Put the lines in order

    Put the lines in order to print the last price using length.

  9. 9. Predict the output

    If the person types 2, what does it print?

  10. 10. Find the case that fails

    last(items) should return the last item, or the text "empty" if the array has nothing in it. Which call makes it fail?

Do this lesson

It opens in your browser. This lesson is part of the full plan; the first unit of each course is free.

See all lessons →