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!

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

Quiz Challenge

Hey everybody. I am having some trouble with the quiz challenge. It will ask the questions but will not give the score or ranking. Everytime I look it up in Javascript console it gives vague errors. Here is my code:

      /*
Quiz Challenge. I will ask a series of five questions and then provide a rank based on their score.
*/
var score = 0;
// Answer variables will be stated as a1, a2, etc. Correct guesses add to the score where as incorrect guesses will add nothing.
var a1= prompt('What city has the largest population?');
if (a1.toUpperCase() === 'TOYKO'){
 score += 1;
} else {
 score += 0;
}
var a2 = prompt('What are the indents on a golf ball called?');
if (a2.toUpperCase() === 'DIMPLES'){
 score+= 1;
} else {
 score += 0;
}
var a3 = prompt('What is the only English word that ends with "mt"?');
if (a3.toUpperCase() === 'DREAMT'){
 score += 1;
} else {
 score += 0;
}
var a4= prompt('What is the largest planet in our solar system?');
if (a4.toUpperCase() === 'JUPITER'){
 score += 1;
} else {
 score += 0;
}
var a5= prompt("What is Rambo's first name?");
if (a5.toUpperCase() = 'JOHN'){
 score += 1;
} else {
 score += 0;
} 
// alert to tell them how many they got right.
document.write('You got ' + score + 'out of 5 correct!');
// Now they will receive a crown rank based on their score
if (score === 5) {
 alert('You received a Gold Crown!');
} else if (score >= 3) {
 alert('You received a Silver Crown!');
} else if (score >= 1) {
 alert('You received a Bronze Crown!');
} else {
 alert('You did not score enough to get a crown. Better luck next time.');
}      

Thank you Jacob for helping me make this question look better.

you can refer to the Markdown Cheat sheet. The Cheat sheet is just above the post comment button. it will tell you how to add your code properly. thanks.

Not a problem. Now lets figure what's going on.

1 Answer

liktid
liktid
6,387 Points

In var a5 you assigned wrong.

var a5= prompt("What is Rambo's first name?");
if (a5.toUpperCase() = 'JOHN')

It should be

var a5= prompt("What is Rambo's first name?");
if (a5.toUpperCase() === 'JOHN')

Hope it helps