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

arik
arik
5,791 Points

My code didn't run at all, and I just got blank page. Could somebody please check what's wrong with my code, thank you.

//variable

var question1; var question2; var question3; var question4; var question5; var numberOfQuestion; var questionLeft; var lastQuestion; var correctScore; var message1;

//Announce the game

alert("Let's start the game!");

//score before the game start correctScore = 0;

//User input

numberOfQuestion = 4; questionLeft = "[" + numberOfQuestion + " questionLeft " + "]"; question1 = prompt("What is the capital of Indonesia?" + questionLeft); question1 = question1.toUpperCase; if(question1 === "JAKARTA"){ correctScore += 1; alert("You are great!"); }else{ alert("The answer was JAKARTA"); }

numberOfQuestion -= 1; questionLeft = "[" + numberOfQuestion + " questionLeft " + "]"; question2 = prompt("What is the capital of Madagascar?" + questionLeft); question2 = question2.toUpperCase; if(question2 === "ANTANANARIVO"){ correctScore += 1; alert("You are great!"); }else{ alert("The answer was ANTANANARIVO"); }

numberOfQuestion -= 1; questionLeft = "[" + numberOfQuestion + " questionLeft " + "]"; question3 = prompt("What is the capital of Micronesia?" + questionLeft); question3 = question3.toUpperCase; if(question3 === "PALIKIR"){ correctScore += 1; alert("You are great!"); }else{ alert("The answer was PALIKIR"); }

numberOfQuestion -= 1; questionLeft = "[" + numberOfQuestion + " question left " + "]"; question4 = prompt("What is the capital of Palau?" + questionLeft); question4= question4.toUpperCase; if(question4 === "NGERULMUD"){ correctScore += 1; alert("You are great!"); }else{ alert("The answer was NGERULMUD"); }

lastQuestion = "[This is the last question. ]" question5 = prompt("What is the capital of Timor Leste?" + lastQuestion); question5 = question5.toUpperCase; if("question5 === "DILI"){ correctScore += 1; alert("You are great!"); }else{ alert("The answer was DILI"); }

//Message

message1 = "<p>You got " + correctScore + " point out of 5 points.</p>"; document.write(message1);

if(correctScore === 5){ document.write("<p><strong>You are awesome! You got gold crown!</strong></p>"); }else if(correctScore>= 3){ document.write("<p>Not bad, you got silver crown!</p>"); }else if(correctScore>= 1){ document.write("<p>You got bronze crown!</p>"); }else{ document.write("<p>You gotta learn more!</p>"); }

3 Answers

lastQuestion = "[This is the last question. ]"; <---add semi-colon...

Remove mismatch quote before 'question5' --->if(question5 === "DILI"){ correctScore += 1; alert("You are great!"); }else{ alert("The answer was DILI"); }

Once I made these changes, it seemed to work fine for me

arik
arik
5,791 Points

Thank you!!! It works:) But I got another problem, despite answering correctly, the program didn't count it, and the last message always return 0 point..It seems that the correctScore+= 1 doesn't work, what could be wrong..

There were some syntax errors..try replacing line 21 with this:

lastQuestion = "[This is the last question. ]"; question5 = prompt("What is the capital of Timor Leste?" + lastQuestion); question5 = question5.toUpperCase; if(question5 === "DILI"){ correctScore += 1; alert("You are great!"); }else{ alert("The answer was DILI"); }

arik
arik
5,791 Points

Thank you for your help robertmaiolo, but could you please highlight which part of the code that has syntax errors, since I couldn't see it. I think the code you gave is the same as mine...

arik
arik
5,791 Points

The problem solved ! I forgot to add --->() after .toUpperCase Instead of writing .toUpperCase() I plainly wrote .toUpperCase. That's why the program always evaluate wrong. Thank you very much indeed robertmaiolo:)