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

Hi! Help needed! (correct.push is not a function)

Hi,

When I try to run the below, it gives me an error, says correct.push is not a function. Any ideas?

Thanks!

// Quiz Game

let questions = [ ['How many days in a week?', 7], ['How many legs has a dog?', 4], ['How many hours in a day', 24] ]

let score = 0; let answer; let question; let response; let correct = []; let incorrect = [];

for (let i = 0; i < questions.length; i += 1) { question = questions [i][0]; answer = questions [i][1]; response = prompt(question); if (response === answer) { score += 1; correct = correct.push(question); } else { incorrect = incorrect.push(question); } }

2 Answers

let questions = [ ['How many days in a week?', 7], ['How many legs has a dog?', 4], ['How many hours in a day?', 24] ];

let score = 0;
let answer; 
let question; 
let response; 
let correct = [];
let incorrect = [];

for (let i = 0; i < questions.length; i++) { 
    question = questions [i][0];

    answer = questions [i][1];

    response =prompt(question); 
    if (response === answer) {
          score += 1;
          //No assignment 
          correct.push(question);

      } else {
        //No assignment
        incorrect.push(question); 

      } 
}

Hi,

Thanks so much for your help.

Ciaran

You are welcome.

Good luck :)