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 Arrays Multidimensional Arrays Build a Quiz Challenge – One Solution

How do I use the '.toUppercase' or '.toLowercase' to stop the correct answer from being case sensitive?

if (response === answer.toLowerCase()) { score++; }

Above is the code I tried to run and I also tried the to.UpperCase but instead of making the response not case sensitive it just meant it had to be lower case or for to.UpperCase it had to be upper case

1 Answer

Austin Whipple
Austin Whipple
29,725 Points

Hi Nicholas,

I suspect what you're trying to do here is do some light sanitization on user input so it more reliably matches the defined answer. For this, you want to use the .toLowerCase() method on the response variable (assuming that's storing what the user is submitting). Something like this:

var answer = 'orange';

if(response.toLowerCase() === answer) { 
 score++;
}

The above code will increment the score with values submitted like 'orange' or 'Orange' or 'ORANGE' and anything in between.

The goal here is to make it more likely that a user submits a matching answer that doesn't require precise capitalization.

Thank you! Yes exactly, looks like I was just putting it the wrong place. Thanks for your help!