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 trialDaniel Kol Adam
3,285 PointsWhy does the program give me silver, when it should be bronze?
This is my code, also the program never shows "Boo" when getting no crowns.
thanks.
// A game that asks the player questions and ranks the player depending on how many correct answers the player answered.
var playerpoints = 0; var question1 = prompt("What is the meaning of life?"); var answer1 = "420"; if (question1 === answer1 || question1 === "blazeit") { playerpoints += 1; }
var question2 = prompt("How tall is the average man in metres?"); var answer2 = "1.7"; if (question2 === answer2 || "1.7 metres") { playerpoints += 1;
}
var question3 = prompt("Is Sushi Halal?"); var answer3 = "Yes" if (question3 === answer3 || question3 === "yes") { playerpoints += 1;
}
var question4 = prompt("Are there only two genders for humans?"); var answer4 = "Yes"; if (question4 === answer4 || question4 === "yes") { playerpoints += 1;
}
var question5 = prompt("How many years has John Oliver been alive?"); var answer5 = "40"; if (question5 === answer5 || "40 miserable years") { playerpoints += 1;
}
if (playerpoints < 1) { alert("Boo"); } else if (playerpoints === 1 || playerpoints === 2) { alert("Well, you got a Bronze Crown"); } else if (playerpoints === 3 || playerpoints === 4) { alert("Congratulations, you have received the Silver Crown"); } else if (playerpoints === 5) { alert("Congrats Gold Crown"); }
//Program end
1 Answer
Steven Parker
231,236 PointsThese two conditional expressions are incomplete:
if (question2 === answer2 || "1.7 metres")
if (question5 === answer5 || "40 miserable years")
Since a non-empty string is considered "truthy", these 2 points are always awarded.