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

DevTools 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?

https://w.trhou.se/4i60mkgj6e

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
seal-mask
STAFF
.a{fill-rule:evenodd;}techdegree
Jennifer Nordell
Treehouse Teacher

Hi 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 :smiley:

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! :sparkles:

Oh, thanks a lot! I can't believe that I missed that! That solved my problem!