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

Using toUpperCase and toLowerCase

Got it this time, sorry guys.

In the code below (I apologize if I was supposed to use some kind of code tags for this post, I'm kind of new), I have written a simple quiz application game for my javascript front end course and my code as is works fine, however when i exchange the toUpperCase's for toLowerCase's I am provided with a false boolean value even if the answer is correct (For example, in my second question "Is a dog an animal?" typing yes gave me a false value when using toLowerCase). Unsatisfied with just knowing the toUpperCase works, I was wondering if anyone could tell me why the toLowerCase that I tried initially did not work. Thank you for your time.

//Quiz application putting together concepts I have been learning, including combined conditional statements
//number correct is 0 at beginning
var numCorrect = 0;
//Questions are asked and correct answers stored
var guess1 = prompt("What is two plus two?");
if (parseInt(guess1) === 4 || guess1.toUpperCase === "FOUR") {
alert("You guessed it right! 1 point");
  numCorrect += 1;
} else {
  alert("Sorry you guessed wrong. No points");
}
var guess2 = prompt("Is a dog an animal?");
if (guess2.toUpperCase === "YES") {
alert("You guessed it right! 1 point");
  numCorrect += 1;
} else {
  alert("Sorry you guessed wrong. No points");
}
var guess3 = prompt("What is the capitol of North Carolina?");
if (guess3.toUpperCase === "RALEIGH") {
alert("You guessed it right! 1 point");
  numCorrect += 1;
} else {
  alert("Sorry you guessed wrong. No points");
}
var guess4 = prompt("How many feet are in a yard?");
if (guess4.toUpperCase === "THREE" || parseInt(guess4) === 3) {
alert("You guessed it right! 1 point");
  numCorrect += 1;
} else {
  alert("Sorry you guessed wrong. No points");
}
var guess5 = prompt("What does html stand for?");
if (guess5.toUpperCase === "HYPER TEXT MARKUP LANGUAGE") {
alert("You guessed it right! 1 point");
  numCorrect += 1;
} else {
  alert("Sorry you guessed wrong. No points");
}
if (numCorrect === 5) {
prize = ' a Gold Crown!'
} else if (numCorrect >= 3) {
prize = ' a Silver Crown!'
} else if (numCorrect >= 2) {
prize = ' a Bronze Crown!'
} else {
prize = ' no prize'
}
document.write('<p>Congratulations! You got ' + numCorrect + ' questions right! you win' + prize + '</p>');

I really apologize for triple posting until i got the code block right. If anyone can also tell me how to delete my other posts on this subject I will gladly do so.

Hey Cody,

That's ok, I have done it for you. Also keep in mind that you can just edit your post by using the "..." at the bottom of your question, a small context menu will pop with "Edit Question" or "Delete Question". :D

3 Answers

Steven Parker
Steven Parker
243,228 Points

When calling a function or method, you must include a set of parentheses after the function name, even if the function does not require any arguments. So instead of:

if (guess2.toUpperCase === "YES") {

You should have:

if (guess2.toUpperCase() === "YES") {

If I understand this question correctly, if you change the condition, then you have to change the answer as well:

if (guess2.toUpperCase() === "YES") {
if (guess2.toLowerCase() === "yes") {

Also include parenthesis () at the end.

Thank you all for the feedback on all of my posts! I will be a better poster next time. I was certainly perplexed and now I understand my mistake. I just wanted to ensure I knew how to properly use methods before moving on to harder projects, those parenthesis slipped my mind.

Cody, you're awesome. Keep on hacking! :)