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

Richard Boag
Richard Boag
5,547 Points

My counter isn't working? Please help

Here's my full code, the prompt boxes come up but the score counter isn't working, at the end it shows 0 correct answers. '''Javascript var counter = 0;

var questionONE = prompt("Is Star Wars an awesome movie?"); var answerOne = questionONE.toLowerCase() === 'true'; if (answerOne === 'yes') { counter += 1; }

var questionTWO = prompt("Is Harry Potter an awesome movie?"); var answerTWO = questionTWO.toLowerCase() === 'true'; if (answerTWO === 'yes') { counter += 1; }

var questionTHREE = prompt("The Matrix, bad movie? Yes or No?"); var answerTHREE = questionTHREE.toLowerCase() === 'true'; if (answerTHREE === 'no') { counter += 1; }

var questionFOUR = prompt("Is Lord of the Rings a great movie?"); var answerFOUR = questionFOUR.toLowerCase() === 'true'; if (answerFOUR === 'yes') { counter += 1; }

var questionFIVE = prompt("Are movies amazing? Yes or No"); var answerFIVE = questionFIVE.toLowerCase() === 'true'; if (answerFIVE === 'yes') { counter += 1; }

document.write('<p>' + 'You got ' + counter + ' answers right.'+'</p>');

if (counter === 5) { document.write('<p>' +'Rank: Gold Crown!'+'</p>'); } else if (counter >= 3 && counter <= 4) { document.write('<p>' +'Rank: Silver Crown!'+'</p>'); } else if (counter >= 2 && counter <= 3) { document.write('<p>' +'Rank: Bronze Crown!'+'</p>'); } else { document.write('<p>' +'Sorry! You get no crown at all!'+'</p>'); } '''

1 Answer

Damien Watson
Damien Watson
27,419 Points

Hi Richard, I had to format it a bit to understand what was going on, below is the functional code. There were two issues.

Issue One

You are setting the answer to the question.lowecase but then comparing to true?

var answerOne = questionONE.toLowerCase() === 'true';

change to

var answerOne = questionONE.toLowerCase();

Issue Two

This might be the copy paste but there are three single quotes at the end of your 'crown' section '''

Updated working code

var counter = 0;

var questionONE = prompt("Is Star Wars an awesome movie?");
var answerOne = questionONE.toLowerCase();
if (answerOne === 'yes') { counter += 1; }

var questionTWO = prompt("Is Harry Potter an awesome movie?");
var answerTWO = questionTWO.toLowerCase();
if (answerTWO === 'yes') { counter += 1; }

var questionTHREE = prompt("The Matrix, bad movie? Yes or No?");
var answerTHREE = questionTHREE.toLowerCase();
if (answerTHREE === 'no') { counter += 1; }

var questionFOUR = prompt("Is Lord of the Rings a great movie?");
var answerFOUR = questionFOUR.toLowerCase();
if (answerFOUR === 'yes') { counter += 1; }

var questionFIVE = prompt("Are movies amazing? Yes or No");
var answerFIVE = questionFIVE.toLowerCase();
if (answerFIVE === 'yes') { counter += 1; }

document.write('<p>' + 'You got ' + counter + ' answers right.'+'</p>');

if (counter === 5) {
    document.write('<p>' +'Rank: Gold Crown!'+'</p>');
} else if (counter >= 3 && counter <= 4) {
    document.write('<p>' +'Rank: Silver Crown!'+'</p>');
} else if (counter >= 2 && counter <= 3) {
    document.write('<p>' +'Rank: Bronze Crown!'+'</p>');
} else {
    document.write('<p>' +'Sorry! You get no crown at all!'+'</p>');
}
Richard Boag
Richard Boag
5,547 Points

How do you get the code to post correctly like that? The triple quotes were listed in the markdown cheat sheet to show as correct code. I'm trying to post my code so it looks like how you posted it.

Damien Watson
Damien Watson
27,419 Points

Yeh, you need to use the single quote in the tilde key (next to the '1' key).

For javascript you can also just use 'js'.