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

Anusha Lee
PLUS
Anusha Lee
Courses Plus Student 14,787 Points

The Conditional Challenge Solution: how come all I got is 0?

Hello everyone,

The following is my code for the first part of this challenge. No matter what I put is yes or no in the prompt answer box, the score added up is zero. What went wrong with my code? Thanks a lot for your kind help.

anusha

var score = 0;
var ans1 = prompt("Is the color of the ocean blue?");
if (ans1.toUpperCase === "YES") {
  score += 1;
}

var ans2 = prompt("Is Taj Mahal in India?");
if (ans2.toUpperCase === "YES") {
  score += 1;
}

var ans3 = prompt("Is Taj Hymalaya the tallest mountain in the world?");
if (ans3.toUpperCase === "YES") {
    score += 1;
}

var ans4 = prompt("Are all leaves green?");
if (ans4.toUpperCase === "NO") {
    score += 1;
}

var ans5 = prompt("Do spiders have 10 legs?");
if (ans5.toUpperCase === "NO") {
    score += 1;
}

document.write("You got total " + score + " scores.");

1 Answer

the toUpperCase is a function/method and therefore needs to have parenthesis after when using it to convert text to uppercase.

try this.

var score = 0;
var ans1 = prompt("Is the color of the ocean blue?");
if (ans1.toUpperCase() === "YES") {
  score += 1;
}

var ans2 = prompt("Is Taj Mahal in India?");
if (ans2.toUpperCase() === "YES") {
  score += 1;
}

var ans3 = prompt("Is Taj Hymalaya the tallest mountain in the world?");
if (ans3.toUpperCase() === "YES") {
    score += 1;
}

var ans4 = prompt("Are all leaves green?");
if (ans4.toUpperCase() === "NO") {
    score += 1;
}

var ans5 = prompt("Do spiders have 10 legs?");
if (ans5.toUpperCase() === "NO") {
    score += 1;
}

document.write("You got total " + score + " scores.");

I hop this helps.