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

JavaScript JavaScript Basics (Retired) Making Decisions with Conditional Statements The Conditional Challenge Solution

My solution (that seems to be working)

As I've never posted here, I thought this would be a great chance to open my post score here on Teamtreehouse.

I think it's so crazy that just around a week ago, I hadn't written a single line of code and now I did this.

Thank you Teamtreehouse!

// First question
let score = 0;
let firstQuestion = prompt("What is the capital of Estonia?").toLowerCase();
if (firstQuestion === "tallinn") {
    score += 1;
    alert("Correct!");
} else {
    score -= 0;
    alert("Wrong!");
}
console.log(firstQuestion + ": Score so far: " + score);

// Second question

let secondQuestion = prompt("What is the capital of Hungary?").toLocaleLowerCase();
if (secondQuestion === "budapest") {
    score += 1;
    alert("Awesome! That's correct!");
} else {
    score -= 0
    alert("That is not correct!");
}
console.log(secondQuestion + ": Score so far: " + score);

// Third question

let thirdQuestion = prompt("What is the capital of Finland?").toLocaleLowerCase();
if (thirdQuestion === "helsinki") {
    score += 1;
    alert("That's correct!");
} else {
    score -= 0;
    alert("That is not correct!");
}
console.log(thirdQuestion + ": Score so far: " + score);

// Fourth question

let fourthQuestion = prompt("What is the capital of Australia?").toLocaleLowerCase();
if (fourthQuestion === "canberra") {
    score += 1;
    alert("That's correct!");
} else {
    score -= 0;
    alert("That is not correct!");
}
console.log(fourthQuestion + ": Score so far: " + score);

// Fifth question

let fifthQuestion = prompt("What is the capital of Bulgaria?").toLocaleLowerCase();
if (fifthQuestion === "sofia") {
    score += 1;
    alert("That's correct!");
} else {
    score -= 0;
    alert("That is not correct!");
    alert("That is the end of the quiz. Thank you!");
}
console.log(fifthQuestion + ": Score so far: " + score);



let prize = "";


if (score === 5) {
    prize = "gold";
} else if (score < 5 && score > 3) {
    prize = "silver";
} else if (score <= 3 && score > 0) {
    prize = "bronze";
} else {
    prize = "nothing";
}
console.log(prize);
alert("You got " + prize);

1 Answer

Steven Parker
Steven Parker
231,275 Points

Good job, and great start on coding! :+1:

One little suggestion: when you have an "if ... else if" chain, you don't need to re-test conditions that would be caught by previous tests, so you can simplify it a bit:

if (score === 5) {
    prize = "gold";
} else if (score > 3) {
    prize = "silver";
} else if (score > 0) {
    prize = "bronze";
// ...

But that's very minor compared to the consolidation you'll be able to achieve when you get to functions.

You're right, it makes more sense. Thank you for the tip!