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 trialKevin Roosey
4,063 PointsThoughts on this code? Any tips for improvement?
var score = 0;
var question1 = prompt("Hello, Welcome to the Quiz App! Question One: What is the lowest point on Earth?"); if (question1.toUpperCase() === "MARIANA TRENCH"){ score ++ } var question2 = prompt("What country was invaded by Germany on September 1st 1939?"); if (question2.toUpperCase() === "POLAND"){ score ++ } var question3 = prompt("What city is the tallest skyscraper in the world located?"); if (question3.toUpperCase() === "DUBAI"){ score ++ } var question4 = prompt("What is the main language spoken in South Africa?"); if (question4.toUpperCase() === "ENGLISH"){ score ++ } var question5 = prompt("What continent is Malta located in?"); if (question5.toUpperCase() === "EUROPE"){ score ++ } alert("You scored " + score + " out of 5");
if (score === 5){ alert("You earned a gold crown!"); } else if (score === 3 || score === 4) { alert("You earned a silver crown!"); } else if (score === 2 || score === 1) { alert("You earned a bronze crown!"); } else { ("You didn't earn a crown, try again next time!"); }
Alexander Davison
65,469 PointsI recommend reading the Markdown Cheatsheet to re-format your code (so that it isn't do yike-y) below the answer box
2 Answers
Alexander Davison
65,469 PointsI re-formatted it for those reading this:
var score = 0;
var question1 = prompt("Hello, Welcome to the Quiz App! Question One: What is the lowest point on Earth?");
if (question1.toUpperCase() === "MARIANA TRENCH") {
score ++
}
var question2 = prompt("What country was invaded by Germany on September 1st 1939?");
if (question2.toUpperCase() === "POLAND") {
score ++
}
var question3 = prompt("What city is the tallest skyscraper in the world located?");
if (question3.toUpperCase() === "DUBAI") {
score ++
}
var question4 = prompt("What is the main language spoken in South Africa?");
if (question4.toUpperCase() === "ENGLISH"){
score ++
}
var question5 = prompt("What continent is Malta located in?");
if (question5.toUpperCase() === "EUROPE"){
score ++
}
alert("You scored " + score + " out of 5");
if (score === 5) {
alert("You earned a gold crown!");
} else if (score === 3 || score === 4) {
alert("You earned a silver crown!");
} else if (score === 2 || score === 1) {
alert("You earned a bronze crown!");
} else {
alert("You didn't earn a crown, try again next time!");
}
Alexander Davison
65,469 PointsYour solution looks great!
There are some more advanced techniques to refactor (clean up) your code, but this code is fine for your level.
Kevin Roosey
4,063 PointsThank you for the tip with the markdown cheatsheet! and thank you for reviewing my code!
Alexander Davison
65,469 PointsYou're very welcome
Kevin Roosey
4,063 PointsKevin Roosey
4,063 PointsYikes that looks horrible. Not sure how to get the actual code into the discussion so that might be the more important question right now lol