Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

JavaScript JavaScript Loops, Arrays and Objects Tracking Multiple Items with Arrays Build a Quiz Challenge, Part 1

David Avila
seal-mask
.a{fill-rule:evenodd;}techdegree
David Avila
Full Stack JavaScript Techdegree Student 5,410 Points

How to push data into 2D arrays at specific positions?

I did my version of the code which apparently works. However, my initial intention was to store wrong answers and questions into another 2D array containing 3 arrays so that I could later iterate through it when reporting the results and output the following: 1- the question that was answered incorrectly, 2- the answer that was provided and 3- the correct answer. Unfortunately I got stuck at pushing information into the inner arrays. Also how/where can I paste code for review?

2 Answers

Steven Parker
Steven Parker
229,771 Points

You can only "push" onto the next free position.

But you can assign to any position. For example:

var x = [];                 // create array "x"
for(let i = 0; i < 3; i++)  // x has 3 inner arrays
  x[i] = [];
x[2][4] = 'test';           // assign to any desired position
x[1][2] = 'this';

If you need help with some code you can always create a question and post it here. Be sure to format your code using the instructions in the Markdown Cheatsheet link at the bottom of the "Add an Answer" section. :arrow_heading_down:

Alexandra Wakefield
Alexandra Wakefield
1,866 Points

For the question, "How/where can I paste code for review," you can paste it here. I don't know if this is the same for you, but the 'Markdown Cheatsheet' linked below the 'Add an Answer' section for me links to the community instead of a helpful formatting sheet. If this is the case for you as well, this link is for Posting Code and here's a Markdown Guide.

Steven Parker
Steven Parker
229,771 Points

You might want to report your link experience as a bug. The instructions for bug reporting are on the Support page.