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 Arrays Store Multiple Values in an Array What is an Array?

MULTIDIMENSIONAL ARRAY

please what is wrong with my code, whenever i run it, they print "response is not defined to the console " i don't know what is wrong with this.

const questions=[
  ['how many planets do we have?' , '8'],
  ['who is the president of Ghana?', 'nana addo'],
  ['how many side does a square have?', '4']

];

let correctAnswers=0;

for(let i=0; i<questions.length; i++){
    let askQuestion=questions[i][0];
    let answer=questions[i][1];
    let response=prompt(askQuestion);
}
if( response===answer ){
    correctAnswers++;
}

document.querySelector('main').innerHTML=
`
<h1>you got ${correctAnswers} question(s) correct</h1>
`;

1 Answer

Steven Parker
Steven Parker
231,172 Points

It looks like you have a closing brace (}) in the wrong place. Right now the "if" comes after the loop and causes the error, but you probably intended to put it inside the loop (where "response" is defined).