Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

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,686 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) { 

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!