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

My Solution to Build a Quiz Challenge(#1)

var correctAnswers = 0
var questionsAns = [
  ['How many continents does our planet have ?', 7],
  ['What school did Cole Tracy attend for his undergrad ?', 'Assumption College'],
  ['How many planets are in our solar system ?', 8],
  ['Where is Assumption College located ?', 'Worcester']
]; 

for ( var i = 0; i < questionsAns.length; i++) {
  var userAnswer = prompt(questionsAns[i][0]);
  if (userAnswer == parseInt(questionsAns[0][1])) {
    correctAnswers += 1
   } else if (userAnswer == questionsAns[1][1].toLowerCase()) {
     correctAnswers += 1
   } else if (userAnswer == parseInt(questionsAns[2][1])) {
     correctAnswers += 1
   } else if (userAnswer == questionsAns[3][1].toLowerCase()) {
     correctAnswers += 1
   }
}

var message = '<p>You got ' + correctAnswers + ' out of 4 questions correct!</p>'

document.write(message);