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![](https://ecs-static.teamtreehouse.com/assets/views/marketing/shared/community-banner-white-47072046c51352fe6a69f5e691ff5700b28bb11d45197d7bdf066d9ea3f72d0c.webp)
![Jason Hill](https://secure.gravatar.com/avatar/43e7faf9fb77ad137c2d916d6d7e007c?s=96&d=https%3A%2F%2Fecs-static.teamtreehouse.com%2Fassets%2Fcontent%2Fdefault_avatar-445fbbabfc8dc9188fb5967fe43322ee0c3e0dd1e10f378bf8343784af5a13eb.webp&r=pg)
Jason Hill
Full Stack JavaScript Techdegree Student 11,399 PointsMy solution
Here is my attempt. Having watched the video I see I could have done the ranking more efficiently via operators, and for some reason my check for crowns == 0, does not work. As well as not using the .toUpperCase, that leaves potential for flawed operation I see. It seems like it should to me though..? Just wanted to post my first draft for criticism while I work out the issue to get input on possible other things. Yes, I'm an electrician by trade :D
// Setting crown variable to zero before storing correct answers
var crowns = 0
// Questions code
var first = prompt("According to ohms law volts x amps = watts, True of False?");
if(first == "true" || first == "True") {
alert("Correct!, you've earned one crown!");
crowns = crowns + 1;
} else
alert("Incorrect!");
var second = prompt("Correct color phases for a 277v 3 phase panel would be Brown, Orange, Yellow. True of False?");
if(second == "true" || second == "True") {
alert("Correct!, you've earned one crown!");
crowns = crowns + 1;
} else
alert("Incorrect!");
var third = prompt("Correct color phases for a 120v 3 phase panel would be Black, Red, Green. True of False?");
if(third == "false" || third == "False") {
alert("Correct!, you've earned one crown!");
crowns = crowns + 1;
} else
alert("Incorrect!");
var fourth = prompt("According to NEC, maximum distance between supports for MC Cable is _FT?");
if(fourth == "6" || fourth == "six") {
alert("Correct!, you've earned one crown!");
crowns = crowns + 1;
} else
alert("Incorrect!");
var fifth = prompt("The maximum number of current carrying conductors allowed in a single raceway before de-rating must be performed is?");
if(fifth == "3" || fifth == "three") {
alert("Correct!, you've earned one crown!");
crowns = crowns + 1;
} else
alert("Incorrect!");
// Crown storage and alerts
if(crowns == 5) {
alert("You've answered 5 out of 5 and earned the gold crown!");
}
else if(crowns == 4) {
alert("You've answered 4 of 5 correct and earn a silver crown!");
}
else if(crowns == 3) {
alert("You've answered 3 of 5 correct and earn a silver crown!");
}
else if(crowns == 1 || 2) {
alert("You've answered less than three correct and earn a bronze crown.");
}
else if(crowns === 0) {
alert("You've answered zero correctly and earn a participation award.");
}
3 Answers
![Steven Parker](https://uploads.teamtreehouse.com/production/profile-photos/969492/micro_tool_chess_set_2.jpg)
Steven Parker
230,688 PointsYou can only combine complete comparison expressions with logical operators.
So instead of "if(crowns == 1 || 2)
", you might write "if (crowns == 1 || crowns == 2)
".
Also, when you get down to the last possible condition, you don't need to test again, you can just use a plain "else" (with no "if").
![Steven Parker](https://uploads.teamtreehouse.com/production/profile-photos/969492/micro_tool_chess_set_2.jpg)
Steven Parker
230,688 PointsWhat was the issue with ".toUpperCase()"? I didn't quite understand that part.
![Jason Hill](https://secure.gravatar.com/avatar/43e7faf9fb77ad137c2d916d6d7e007c?s=96&d=https%3A%2F%2Fecs-static.teamtreehouse.com%2Fassets%2Fcontent%2Fdefault_avatar-445fbbabfc8dc9188fb5967fe43322ee0c3e0dd1e10f378bf8343784af5a13eb.webp&r=pg)
Jason Hill
Full Stack JavaScript Techdegree Student 11,399 PointsWell if they typed TRUE it would fail due to my condition being true or True. In instructor solution he covered that.
![Steven Parker](https://uploads.teamtreehouse.com/production/profile-photos/969492/micro_tool_chess_set_2.jpg)
Steven Parker
230,688 PointsThat's where it can be handy, for example, this will catch any spelling:
if (first.toUpperCase() == "TRUE") {