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!
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

Nelson J
7,411 PointsFeedback on my simple solution, however it took me forever to come up with it.
/* Ask at least five questions
Keep track of the number of questions the user answered correctly
Provide a final message after the quiz letting the user know the number of questions he or she got right.
Rank the player. If the player answered all five correctly, give that player the gold crown: 3-4 is a silver crown; 1-2 correct answers is a bronze crown and 0 correct is no crown at all.
*/
var count = 0;
var country = prompt("Are you in the US?");
if(country === 'yes') {
count++;
}
var hasDog = prompt("Do you have a dog?");
if(hasDog === 'yes') {
count++;
}
var likesRock = prompt("Do you like rock music");
if(likesRock === 'yes') {
count++;
}
var knowsJavascript = prompt("Do you know javascript");
if(knowsJavascript === 'yes') {
count++;
}
var whoIs = prompt("Are you Nelson");
if(whoIs === 'yes') {
count++;
}
if(count === 5) {
alert('Gold Crown');
}
else if(count <= 4 && count >= 3) {
alert('silver crown');
}
else if(count <= 2 && count >= 1) {
alert('Bronze crown');
}
else {
alert('no crown');
}

Carl Evison
2,656 PointsI would like to point out if the users types Yes
they won't be awarded the point because of the strict comparison Yes is not equal to yes.
So you should convert their input to lower case.

Nelson J
7,411 PointsSteven Parker thanks for pointing that out. I have fixed it. @ Carl Evison thank you for your feedback too. Will make it more flexible.
1 Answer

Steven Parker
225,770 PointsI often take Carl's suggestion one step further and allow anything that starts with "y" (like "Yes", "yo", "yup", etc.) to be taken as an affirmative response:
var ask = question => prompt(question).toLowerCase().startsWith("y");
// then later...
if (ask("Do you know JavaScript? ")) {
Steven Parker
225,770 PointsSteven Parker
225,770 PointsTo preserve the appearance of your code, use Markdown formatting. There's a video about it.