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

Nick East
Nick East
7,671 Points

Help why am i always getting 1/5, even though i answer the questions correctly!!

// quiz starts - no questions have been asked 
var correct = 0; 

//ask a quesiton 
var  question1 = prompt("Name a programming language that is also a gem?");
if (question1.toUpperCase() === "RUBY")  {
    correct +=  1;
    }

var question2 = prompt("What does HTML stand for?");
if (question2.toUpperCase() === "HYPER TEXT MARKUP LANGUAGE") {
    correct += 1;
    }


var question3 = prompt("What does CSS stand for?");
if (question3.toUpperCase () === "CASCADING STYLE SHEETS" ) {
    correct +=  1;
    }

var question4 = prompt("True or False,  JavasScipt & Java the same programming language");
if (question4.toUpperCase() === "FALSE" ) {
    correct =+ 1;
}

var question5 = prompt("True or False, JavaScript can work on the back end as well as the front?")
if (question5.toUpperCase() === "True" ) {
    correct =+ 1;
    }
//Out-put result
document.write("<p>You got " + correct + " out of 5 questions correct.<p>");

if ( correct === 5 ) {
  document.write("<p><strong>You earned a gold crown!</strong></p>");  
} else if (correct >= 3) {
  document.write("<p><strong>You earned a silver crown.</strong></p>");  
} else if (correct >= 2) {
  document.write("<p><strong>You earned a bronze crown.</strong></p>");  
} else {
  document.write("<p><strong>Hahahahah you lose</strong></p>");
}

1 Answer

A couple issues seems to be causing the issue.

  1. Question 4 and 5 += assignment operator is backwards =+.
  2. Question 5 you're converting the prompt response toUpperCase, but the answer is lowercase. question5.toUpperCase() === "True"
// quiz starts - no questions have been asked 
var correct = 0; 

//ask a quesiton 
var  question1 = prompt("Name a programming language that is also a gem?");
if (question1.toUpperCase() === "RUBY")  {
    correct +=  1;
    }

var question2 = prompt("What does HTML stand for?");
if (question2.toUpperCase() === "HYPER TEXT MARKUP LANGUAGE") {
    correct += 1;
    }


var question3 = prompt("What does CSS stand for?");
if (question3.toUpperCase() === "CASCADING STYLE SHEETS") {
    correct +=  1;
    }

var question4 = prompt("True or False,  JavasScipt & Java the same programming language");
if (question4.toUpperCase() === "FALSE") {
    correct += 1;
}

var question5 = prompt("True or False, JavaScript can work on the back end as well as the front?");
if (question5.toUpperCase() === "TRUE") {
    correct += 1;
    }
//Out-put result
document.write("<p>You got " + correct + " out of 5 questions correct.<p>");

if ( correct === 5 ) {
  document.write("<p><strong>You earned a gold crown!</strong></p>");  
} else if (correct >= 3) {
  document.write("<p><strong>You earned a silver crown.</strong></p>");  
} else if (correct >= 2) {
  document.write("<p><strong>You earned a bronze crown.</strong></p>");  
} else {
  document.write("<p><strong>Hahahahah you lose</strong></p>");
}
Nick East
Nick East
7,671 Points

Thank you so much! Knew it was something small!