Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

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 {

}