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

Niki Molnar
Niki Molnar
25,698 Points

Alternative right/wrong solution to 2-dimensional array quiz?

Rather than add two more arrays for right and wrong answers, why wouldn't you push a true or false to the end of each question i.e.:

if(response === answer) { questions[i].push(true); } else { questions[i].push(false); }

then loop through the question array for which question were right and wrong.

My question is, doesn't creating new arrays take additional server time/resources?

2 Answers

Steven Parker
Steven Parker
243,656 Points

These arrays are not created in the server.

Your JavaScript code is executed in the user's browser.

But your idea might help reduce memory usage when the number of questions was really huge, since you would be only storing a boolean instead of a copy of the question. But you could also make the program more memory-efficient by saving the question index instead of the question itself in the separate array. Having multiple arrays doesn't require more system or memory resources if the total storage space is the same.

Niki Molnar
Niki Molnar
25,698 Points

Thanks - that's helpful