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 trialTayfun İlbakan
6,977 PointsDevTools gives me error of "Uncaught TypeError: Cannot read property '0' of undefined at quiz.js:10"
I've checked everything with Guil's code but it seems perfectly similar to me, but when I execute it, after answering first question, it stops working and I'm having an error as "Uncaught TypeError: Cannot read property '0' of undefined at quiz.js:10"
Can you help me what is causing that?
const questions = [ ['Which year is it?', '2021'], ['What is your name?', 'Tayfun'] ['Whats your home country?', 'Turkey'] ];
let correctAnswers = 0;
for ( let i = 0; i < questions.length; i++ ) { let question = questions[i][0]; let answer = questions[i][1]; let response = prompt(question);
if ( response === answer) { correctAnswers++; } }
let html =
<h1>You got ${correctAnswers} question(s) correct</h1>
;
document.querySelector('main').innerHTML = html;
2 Answers
Jennifer Nordell
Treehouse TeacherHi there, Tayfun İlbakan ! You're doing great. The problem here is a single comma. Namely, you're missing a comma in your questions
between the nested arrays so questions
isn't really declared like it should be
You have this:
const questions = [
['Which year is it?', '2021'],
['What is your name?', 'Tayfun']
['Whats your home country?', 'Turkey']
];
But you need:
const questions = [
['Which year is it?', '2021'],
['What is your name?', 'Tayfun'], // there was a missing comma right here
['Whats your home country?', 'Turkey']
];
Hope this helps!
Tayfun İlbakan
6,977 PointsOh, thanks a lot! I can't believe that I missed that! That solved my problem!