tracks

Sign In Sign Up
9/13
Introduction to 'For' Loops in JS
Meet arrays

Variables can store numbers or strings. But so far, we've only been able to store ONE number or ONE string. Good thing we have arrays. Arrays:

a. store lists of data
b. can store different data types at the same time
c. are ordered so the position of each piece of data is fixed

Example:

var names = ["Mao","Gandhi","Mandela"];

var sizes = [4, 6, 3, 2, 1, 9];

var mixed = [34, "candy", "blue", 11];

Syntax:
var arrayName = [data, data, data];

Any time you see data surrounded by [ ], it is an array.

Instructions

Make your own array called junk. Put 4 bits of data in it (first 2 strings, then 2 numbers).

  1. Declare it using var.
  2. Put [ ] around your data.
  3. Separate each bit of data with a comma.
  4. End it with a semi-colon.
  5. Use console.log to print out junk.
?
Stuck? Get a hint! Hint

Check out the examples in the instructions if you need help!

script.js
Back to Editor

Sign in