Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

JavaScript

Victor Gentile
Victor Gentile
4,996 Points

How do I make the final message about which crown the user has won...

have written all of the code and it all works properly... can't seem to let the user know which if any of the crowns he/she has won?

11 Answers

It's part of learning. On the last error just delet the alert(message); that should fix your integre problem.

You should post the code so we can better help you:)

Victor Gentile
Victor Gentile
4,996 Points

workspaces won't let me copy anything... guess I should re-write the entire code..???here

Victor Gentile
Victor Gentile
4,996 Points

var correctAnswers = 0;

var input1 = prompt("How much is 7 - 3 ?"); if (parseInt(input1) === 4){ correctAnswers += 1; alert("That is the right answer."); } else { alert("Sorry. Your answer is incorrect."); }

var input2 = prompt("How much is 9 - 6 ?"); if (parseInt(input2) === 3){ correctAnswers += 1; alert("That is the right answer."); }else { alert("Sorry. Your answer is incorrect."); }

var input3 = prompt("How much is 8 - 4 ?"); if (parseInt(input3) === 4){ correctAnswers += 1; alert("That if the right answer."); }else{ alert("Sorry. Your answer is incorrect."); }

var input4 = prompt("How much is 5 - 1 ?"); if (parseInt(input4) === 4){ correctAnswers += 1; alert("That is the right answer."); }else{ alert("Sorry. Your answer is incorrect."); }

var input5 = prompt("How much is 7 - 6 ?"); if (parseInt(input5) === 1){ correctAnswers += 1; alert("That is the right answer."); }else{ alert("Sorry. Your answer is incorrect."); }

var message = correctAnswers; if (count === 0){ alert("You haven't won anything."); }else if (count >=1 && count <=2){ alert("You have won the Bronze Crown."); }else if (count >=3 && <=4) { alert("You have won the Silver Crown."); }else{ alert("You have won the GOLD CROWN !"); }

alert(message);

/* var message = "You have answered " + correctAnswers + " questions correctly.";

alert(message); */

Victor Gentile
Victor Gentile
4,996 Points

lol... this is not what it looks like on my workspace...

Replace The count with the correctAnswers variable, like this.

var message = correctAnswers; if (correctAnswers === 0){ alert("You haven't won anything."); } else if (correctAnswers >=1 && correctAnswers <=2){ alert("You have won the Bronze Crown."); } else if (correctAnswers >=3 && correctAnswers <=4){ alert("You have won the Silver Crown."); } else{ alert("You have won the GOLD CROWN !"); }

that should work since the correctAnswers is where your storing your correct answers. count should not be there since dose not seem like you have created a variable for it.

Victor Gentile
Victor Gentile
4,996 Points

Thanks... I have tried that already... but I coded it again just as you suggested. I save the page and when I relaunch it in chrome... the page loads with the heading but no alert boxes appear... nothing. I've been trying to work around this for hours. Again, thank you... still tryin...

Victor Gentile
Victor Gentile
4,996 Points

Just tried it again... I had omitted one of the "correctAnswers" ... it's working now except after it runs the alert about which crown I've won... it gives another alert with just the integer. If its a gold crown, the alert goes away and another alert appears with just the number 5... weird.

Victor Gentile
Victor Gentile
4,996 Points

Most of my mistakes are oversights and spelling errors... gets frustrating... trying to slow down and check everything...

On your silver crown else if statement, make sure your adding another correctAnswers variable to the argument like this correctAnswers<=4. You were missing a comparison on the code you first sent.

Victor Gentile
Victor Gentile
4,996 Points

yes I caught that.... thanks for your time and consideration.

No problem