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 Basics (Retired) Making Decisions with Conditional Statements The Conditional Challenge

3 Answers

Very good. you can improve it by making a multi dimensional array that contain 2 elements. index 0 is for storing the question and index 1 is for storing the answers.

that way u can just access each element in a for loop that : for(let i=0; i< someArray.length; i++) { const question = someArray[i][0] const answer = someArray[i][1]

// perform some code }

this way u access each array in the multidimensional array every iteration and perform an if statement each iteration to check if the user entered the right answer

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

Thanks! Because we hadn't gotten to arrays, objects, or even loops at this point, I didn't attempt to make it more efficient. I definitely think using key:value pairs is the way to go here.

Thanks for the great feedback!

You can also chain the if statement with an else if.

if(some code) {

} else if(some code) {

} else if(some code) {

} else {

}