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 trialIjac Mihai
6,976 PointsI don't know what is wrong here
// quiz begin no answers correct var correct = 0; // ask question var answer1 = prompt("Name a programing language who's also a gem"); if ( answer1.toUpperCase() === 'RUBY'){ correct += 1; }
var answer2 = prompt("Name a programing language who's also a gem"); if ( answer1.toUpperCase() === 'RUBY'){ correct += 1; }
var answer3 = prompt("Name a programing language who's also a gem"); if ( answer1.toUpperCase() === 'RUBY'){ correct += 1; }
var answer4 = prompt("Name a programing language who's also a gem"); if ( answer1.toUpperCase() === 'RUBY'){ correct += 1; }
var answer5 = prompt("Name a programing language who's also a gem"); if ( answer1.toUpperCase() === 'RUBY'){ correct += 1; } //output document.write("<p> you got" + correct + "out of 5 questions</p>"); //output rank 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> }
1 Answer
Martin Balon
43,651 PointsHi Mihai,
You are always comparing variable answer1 = so variable correct will be either 0 or 5 based on first answer. Also you are missing a quotation marks in the last if else statement - that's probably why your code doesn't work. Document.write is considered as bad practice.
http://stackoverflow.com/questions/802854/why-is-document-write-considered-a-bad-practice
Here's you code after small adjustments, just copy and paste it into to console and hit enter.
// quiz begin no answers correct
var correct = 0;
// ask question
var answer1 = prompt("Question 1/5: Name a programming language who's also a gem");
if ( answer1.toUpperCase() === 'RUBY'){
correct += 1;
}
var answer2 = prompt("Question 2/5: Name a programming language who's also a gem");
if ( answer2.toUpperCase() === 'RUBY'){
correct += 1;
}
var answer3 = prompt("Question 3/5: Name a programming language who's also a gem");
if ( answer3.toUpperCase() === 'RUBY'){
correct += 1;
}
var answer4 = prompt("Question 4/5: Name a programming language who's also a gem");
if ( answer4.toUpperCase() === 'RUBY'){
correct += 1;
}
var answer5 = prompt("Question 5/5: Name a programming language who's also a gem");
if ( answer5.toUpperCase() === 'RUBY'){
correct += 1;
}
//output
alert("you got " + correct + " out of 5 questions");
//output rank
if(correct === 5){
alert("You earned a gold crown!");
} else if (correct >= 3) {
alert("You earned a silver crown!");
}
JOSE PAEZ
7,566 PointsJOSE PAEZ
7,566 PointsThanks!!