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 trialarmen
3,753 Points[SOLVED] Help with code - crown type not changing
My score variable changes fine but my crownType variable is staying as "bronze" for some reason.
Any ideas why?
var message = alert("Get ready for the quiz!");
var score = 0;
var crownType = "";
var questionOne = prompt("Is the sun hot?");
if ( questionOne.toUpperCase() === "YES" ) {
score += 1;
}
var questionTwo = prompt("Do snakes have arms?");
if ( questionTwo.toUpperCase() === "NO" ) {
score += 1;
}
var questionThree = prompt("Do laptops use electricity?");
if ( questionThree.toUpperCase() === "YES" ) {
score += 1;
}
var questionFour = prompt("Do cars use gas?");
if ( questionFour.toUpperCase() === "YES" ) {
score += 1;
}
var questionFive = prompt("Is there such thing as 'hybrid' vehicles?");
if ( questionFive.toUpperCase() === "YES" ) {
score += 1;
}
if (score === 0 || 1 ) {
crownType = "bronze";
}
else if ( score === 2 || 3 ) {
crownType = "silver";
}
else {
crownType = "gold";
}
message = alert("All done! you scored " + score + "/5. you earned a " + crownType + " crown!");
1 Answer
Karen Freeman-Smith
29,248 PointsI've been doing a lot more JavaScript lately than Java, but this looks suspicious: (score === 0 || 1 )
I would expect (score===0 || score===1) otherwise the 1 would represent "true" every time.
armen
3,753 PointsThanks! that's exactly what I needed.
Nate Conley
16,191 PointsNate Conley
16,191 PointsWould you mind submitting your code using Markdown? There is a Markdown Cheatsheet below the textarea.