thecodezone.
The Code Zone
Short steps, at your pace · Free lessons and practice · Member video walkthroughs
Save your next small win.

Checking your account…

19.12 · Arrays / Practice · 6 min

Choose a row, then an item

Use two positions to read a number, a color and a Boolean.

Activity 12 of 15 in Arrays

All courses

JavaScript Basics / 19.12

Choose a row, then an item

Not started

Use two positions to read a number, a color and a Boolean.

More options
Rob selects 30 in row 0, green in row 1 and the first true in row 2.
Rob’s comic strip · Arrays

Follow two indexes into a nested array

Work through 4 focused steps. Read the explanation, type each requested change and check it before moving on. Your own code carries forward.

The mini-lesson opens in a new tab. Your own code carries forward; each step has a focused check and an optional hint.

Start mini-lesson(opens in a new tab)

4 steps · Saved work · Instant feedback

YOUR TURN

Choose a row, then an item

Repair the three bracket accesses without loops. From the provided nestedArray print Number: 30, Color: green, and Flag: true. The first index chooses an inner array; the second chooses an element inside it. Keep the data and output labels; do not replace the accesses with literal answers.

Expected output
Number: 30
Color: green
Flag: true

Keep the starting inputs. Print these lines in this order, without extra output.

Edit JavaScript, then run it. Check Challenge shows which output checks pass or need a fix. Word wrap is enabled.

Ready to checkRun the checks to see your results here.

Work in VS Code instead

Copy the starter into a file named practice.js in VS Code. If Node.js is installed, open the terminal in that folder and run node practice.js. Compare the output with the task above. Automated challenge checks are available in the browser editor.

Code example
example.jsjavascript · example
const nestedArray = [
  [10, 20, 30],
  ["red", "green", "blue"],
  [true, false, true],
];
console.log("Number: " + nestedArray[0][1]);
console.log("Color: " + nestedArray[1][0]);
console.log("Flag: " + nestedArray[2][1]);

Need a nudge?

Read brackets from left to right

nestedArray[0] is the numbers row. Accessing [2] on that row selects its third value. Both levels start at zero.

Each inner array has its own indexes

The colors row is outer index 1; green is its inner index 1. The Boolean row is outer index 2; its first true is inner index 0.

Replace your editor code?

Your current work will be replaced. Choose Cancel to keep it.

Ready to try it?

Practice in your browser and see your results.

Progress details

Have a question?

Ask the Code Zone community.

Ask a question in The Code Zone (opens in a new tab)

Continue learning

ONE STEP FORWARD

Read one value at a time and keep track of what each index or total means.