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 trialAnastasios Ioannou
3,616 PointsMy code doesn't give the right score of correct answers...
Hello,
I was trying to solve the challenge, so I have been making the 5 questions and provided a variable for the score of correct questions answered.
The code is pretty straight forward but for some reason it never gives me the correct answer of questions added. I have trying for quite a while to try and solve the problem but I can't. Even the solution the tutor gave in the video seems exactly the same only instead of "correct" I have named my variable "score"
Could you please help me with this?
Looking forward for your answer!
My code looks like this:
var score = 0;
var firstQuestion = prompt("Name the capital of Greece?");
if ( firstQuestion.toUpperCase() === "ATHENS" ) {
score +=1;
}
var secondQuestion = prompt("Name the capital of Albania?");
if ( secondQuestion.toUpperCase() === "TIRANA" ) {
score =+1;
}
var thirdQuestion = prompt("Name the capital of Bulgaria?");
if ( thirdQuestion.toUpperCase() === "SOFIA" ) {
score +=1;
}
var fourthQuestion = prompt("Name the capital of Romania?");
if ( fourthQuestion.toUpperCase() === "BUCURESTI" ) {
score +=1;
}
var fifthQuestion = prompt("Name the capital of Serbia?");
if ( fifthQuestion.toUpperCase() === "BELGRADE" ) {
score +=1;
}
document.write("<p>You got " + score + " answers correct.</p>")
1 Answer
Ethan Rivas
9,979 PointsI don't know if this is gonna solve all your code but I see that in your second "if" there's a little error:
if ( secondQuestion.toUpperCase() === "TIRANA" ) {
score +=1;
}
- This works for me:
var score = 0;
var firstQuestion = prompt("Name the capital of Greece?");
if ( firstQuestion.toUpperCase() === "ATHENS" ) {
score +=1;
}
var secondQuestion = prompt("Name the capital of Albania?");
if ( secondQuestion.toUpperCase() === "TIRANA" ) {
score +=1;
}
var thirdQuestion = prompt("Name the capital of Bulgaria?");
if ( thirdQuestion.toUpperCase() === "SOFIA" ) {
score +=1;
}
var fourthQuestion = prompt("Name the capital of Romania?");
if ( fourthQuestion.toUpperCase() === "BUCURESTI" ) {
score +=1;
}
var fifthQuestion = prompt("Name the capital of Serbia?");
if ( fifthQuestion.toUpperCase() === "BELGRADE" ) {
score +=1;
}
document.write("<p>You got " + score + " answers correct.</p>")
Anastasios Ioannou
3,616 PointsAnastasios Ioannou
3,616 Pointsyes....these typos... :)
Thank you very much for your answer!!