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

Brent Robinson
seal-mask
.a{fill-rule:evenodd;}techdegree
Brent Robinson
Full Stack JavaScript Techdegree Student 3,828 Points

I used a while loop and didn't use a counter, is this alright? or is it too much code for what is necessary?

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

var quizQuestions = [
  ['what is 5 + 4?', '9'],
  ['what is 4 + 4?', '8'], 
  ['what is 3-2?', '1'],
]

var questionOne =  prompt(quizQuestions[0][0]);
var questionTwo = prompt(quizQuestions[1][0]);
var questionThree = prompt(quizQuestions[2][0]);

while (false) {
  prompt(questionOne[0]);
  prompt(questionTwo[1]);
  prompt(questionThree[2]);
  break;
}

if (questionOne === quizQuestions[0][1]) {
  print('<h1>you got number 1 right!</h1>');
} else {
  print('<h1>you got number 1 wrong!</h1>');
}

if (questionTwo === quizQuestions[1][1]) {
  print('<h1>you got number 2 right!</h1>');
} else {
  print("<h1>you got number 2 wrong!</h1>");
}

if (questionThree === quizQuestions[2][1]) {
  print("<h1>you got number 3 right!</h1>");
} else {
  print("<h1>you got number 3 wrong</h1>");
}

I used h1 tags to separate the text onto different lines. I noticed if i just used the print it would print in a single line

this is for Build a Quiz Challenge, Part 1

1 Answer

Brendan Whiting
seal-mask
.a{fill-rule:evenodd;}techdegree seal-36
Brendan Whiting
Front End Web Development Techdegree Graduate 84,735 Points

This block of code never gets run because the condition is false:

while (false) {
  prompt(questionOne[0]);
  prompt(questionTwo[1]);
  prompt(questionThree[2]);
  break;
}

Also it seems like that code isn't necessary because you're prompting for the answers and checking the answers in other code anyways and it seems to work.