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 trialJack Camp
6,121 PointsMy code only prints a score of 0?
Every time I run this program the score of 0 always comes up even when you answer the questions correctly ?
var score = 0;
//START OF QUESTIONS var questionOne = prompt("What colour is the door?"); if (questionOne.toUpperCase === "GREEN") { score += 1; }
var questionTwo = prompt("What colour is the phone?"); if (questionTwo.toUpperCase === "BLACK") { score += 1; }
var questionThree = prompt("What are you coding with?"); if (questionThree.toUpperCase === "TREEHOUSE") { score += 1; }
var questionFour = prompt("What's the best phone?"); if (questionFour.toUpperCase === "SAMSUNG") { score += 1; }
var questionFive = prompt("What's the best name?"); if (questionFive.toUpperCase === "JACK") { score += 1; } //END OF QUESTIONS
//SCORING AND RANKING THE PLAYER if (score === 5) { document.write("<p>GOLD! You got the gold crown and scored " + score + " points!</p>"); } else if (score >= 3) { document.write("<p>Not bad! You got the silver crown with " + score + " points!</p>");
} else if (score <= 2) { document.write("<p>Could be better! You got " + score + " points. You get the bronze crown.</p>");
} else { document.write("<p>Oh no! you got no crown! " + score + " points at all!</p>"); }
2 Answers
Henrik Christensen
Python Web Development Techdegree Student 38,322 PointsWhen trying to call a method you need to add () to the end of the method.
toUpperCase is a method but you forgot the () at the end :-)
luisgomez7
5,557 PointsHey Henrik: I ran into the same problem. Then I watched the video closely. It was the teacher in the video who made that mistake, leaving us students to scratch our heads and wonder why our programs aren't running correctly. The mistake occurs NO LESS THAN FOUR TIMES at lines 10, 14, 18 and 22. I also noticed the teacher didn't bother to run the program. Had he done that he would have gotten the same results we did.
Jack Camp
6,121 PointsJack Camp
6,121 PointsAh! Thank you!