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

If condition not working

I used this if condition but it ain't working

alert("Here we go");
var agree = prompt("Are you ready?");
console.log("Variable created");
if (agree.toUpperCase === "YES" || agree.toUpperCase === "Y") {
  // Quiz code
  console.log("Hello");
  alert("Condition passed");
}else {
alert("Okay. Refresh the page if you change your mind.");
}

2 Answers

Steven Parker
Steven Parker
243,656 Points

toUpperCase is a function. To call a function, you have to include the parentheses () after it, whether you are passing arguments or not. Without the parentheses, you are just naming the function.

Thanks. That's 4 stupid mistakes I've done so far...

Steven Parker
Steven Parker
243,656 Points

Mistakes are not stupid. They are valuable learning opportunities. :smile:

Speaking of mistakes, ignore what I said about "YES", I was thinking you were just checking the first letter.

Yep, but sometimes I feel stupid. Thanks though!