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

Why is this test for lower case strings failing?

Here's my simplified code. The problem is the ".toLowerCase". If I omit that, the test works fine (as do the other 4 I omitted here.) A JS linter finds no problems, but it fails to do the test below. If I add the "() to the ".toLowerCase", then it works, but Dave's example video doesn't have them. Any clues?

// Created by John on 08/23/2015

//set correct answers to zero
var questionsRight = 0;

// ask at least 5 questions
var currentPOTUS = prompt('Who is the current President of the US?');

// Testing - this string shows up in the log
console.log(currentPOTUS);

//Testing the answers set to lower case

if (currentPOTUS.toLowerCase === "barack obama" || currentPOTUS.toLowerCase === "obama") {
    console.log(currentPOTUS.toLowerCase); // doesn't log
    console.log(currentPOTUS); // doesn't log
    questionsRight++;
}

// Provide a final message after the quiz letting the user know the number of questions he or she got right.

document.write('You got ' + questionsRight + ' questions right.');

// Rank the player. If the player answered all 5 questions correctly, give that player the gold crown.
// 3 - 4 is a silver crown; 1- 2 is a bronze crown and 0 is no crown at all.

if (questionsRight === 5) {
    document.write('You are hearby awarded a gold crown!');
} else if (questionsRight >= 3) {
    document.write('You are hearby awarded a silver crown!');
} else if (questionsRight > 0) {
    document.write('You are hearby awarded a bronze crown');
} else {
    document.write('You didn\'t win a crown, but thanks for playing!');
}

Hi can you please upload the code of your project not just simplified but as you have written in workspaces take a snapshot if you like then give the link.

//Fixed Code Presentation

4 Answers

Byron Stine
Byron Stine
4,877 Points

Sorry Jack. I should have read your question better. In his video he has the parentheses on the first declaration of the .toUpperCase method, but then omits them after the first one.

Byron Stine
Byron Stine
4,877 Points

the .toLowerCase() method requires the parentheses. In your code you have currentPOTUS.toLowerCase. If you add the parentheses like so: currentPOTUS.toLowerCase(), then it should work. Happy coding!

Hi Byron,

Actually, if you look I said exactly the same thing.

My question is why Dave's example code doesn't have the (), but works. Is it a mistake, or is there something different about .toUpperCase and .toLowerCase.

Regards,

Jack

Hi Byron,

Thanks for pointing this out - I missed the inconsistency. I'll report it.

Regards,

Jack

Samuel Webb
Samuel Webb
25,370 Points

This is a mistake in the code. You are correct that .toUpperCase() requires the parenthesis every time you use it. I'd guess Dave was recently using some other language like Ruby in which you don't have to use parenthesis to invoke functions/methods so he didn't catch the mistake.

Dave McFarland please take a look.

So, does that qualify for an exterminator badge?