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

William Coshburn
William Coshburn
5,431 Points

I get an error right away with my 3rd question , then I get another with call to the variable question

question = questions[i][0];

console says that it cannot read the property '0'.

Can this quiz be created without the arrays?

3 Answers

William Coshburn
William Coshburn
5,431 Points

I appreciate it, it's probably just me being awful at this. I couldn't even get this started. I would have done this without the arrays.

var questions = [

['Who is the GOAT?', 'Michael Jordan'] ['Where do the Cowboys play?', 'Dallas']

];

var correctAnswers =0; var question; var response; var html;

for( var i=0; i < questions.length; i+=1) {

question = questions[i][0]; answer = questions[i][1]; response = toLowerCase(prompt(question)); }

function print(message) { document.write(message); }

Ahmad Asyraf Bin Kamsir
Ahmad Asyraf Bin Kamsir
3,417 Points

your question states that you are having a problem with your third question but you only posted two.

"Who is the Goat?" and "Where do the Cowboys play?"

Upon observation of your code. you have set the response to lowercase but you set the answers (Michael Jordan, Dallas) with capitals.

I would also move your function print(message){ { document.write(message);} outside your for loop. I would put it right after you are declaring your variables.

simply, I see you don't have comma to split the sub arrays.