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 Making Decisions in Your Code with Conditional Statements The Conditional Challenge Solution

Amrit Ramos
PLUS
Amrit Ramos
Courses Plus Student 5,256 Points

Where can I add the .toLowerCase() code in my code

Hi. I keep wanting to add the .toLowerCase() somewhere into my code. I've tried various places but it does not work. Does someone have any idea as to where I could add it for it to work? Below is my code:

let userScore = (0);
let userRank;

const answer1 = ("blue");
const answer2 = ("green");
const answer3 = ("orange");
const answer4 = ("black");
const answer5 = ("red");

const question1 = prompt("What color is the sky?");



// this the code to give the user its score

if (question1 === answer1) {
  userScore +=1;
  }

const question2 = prompt("What color are the trees?");
if (question2 === answer2) {
  userScore +=1;
  } 

const question3 = prompt("What color is an orange?");
if (question3 === answer3) {
  userScore +=1;
  } 

const question4 = prompt("What color is a black pen?");
if (question4 === answer4) {
  userScore +=1;
  } 

const question5 = prompt("What color is a strawberry?");
if (question5 === answer5) {
  userScore +=1;
  } 



// this the code to give the user its ranking
if (userScore === 5){
  userRank = ("Gold");
 } else if (userScore >= 3) {
   userRank = ("Silver");
 } else if (userScore >=1){
   userRank = ("Bronze");
 } else { 
   userRank = ("you did not get a");
 }

3 Answers

let userScore = (0);
let userRank;

const answer1 = ("blue");
const answer2 = ("green");
const answer3 = ("orange");
const answer4 = ("black");
const answer5 = ("red");

//Not practical but you can add .toLowerCase to the end of every prompt
const question1 = prompt("What color is the sky?").toLowerCase();



// this the code to give the user its score

if (question1 === answer1) {
  userScore +=1;
  }

const question2 = prompt("What color are the trees?").toLowerCase();
if (question2 === answer2) {
  userScore +=1;
  } 

const question3 = prompt("What color is an orange?").toLowerCase();
if (question3 === answer3) {
  userScore +=1;
  } 

const question4 = prompt("What color is a black pen?").toLowerCase();
if (question4 === answer4) {
  userScore +=1;
  } 

const question5 = prompt("What color is a strawberry?").toLowerCase();
if (question5 === answer5) {
  userScore +=1;
  } 



// this the code to give the user its ranking
if (userScore === 5){
  userRank = ("Gold");
 } else if (userScore >= 3) {
   userRank = ("Silver");
 } else if (userScore >=1){
   userRank = ("Bronze");
 } else { 
   userRank = ("you did not get a");
 }
let userScore = (0);
let userRank;

const answer1 = ("blue");
const answer2 = ("green");
const answer3 = ("orange");
const answer4 = ("black");
const answer5 = ("red");

//Not practical but you can add .toLowerCase to the end of every prompt
const question1 = prompt("What color is the sky?").toLowerCase();



// this the code to give the user its score

if (question1 === answer1) {
  userScore +=1;
  }

const question2 = prompt("What color are the trees?").toLowerCase();
if (question2 === answer2) {
  userScore +=1;
  } 

const question3 = prompt("What color is an orange?").toLowerCase();
if (question3 === answer3) {
  userScore +=1;
  } 

const question4 = prompt("What color is a black pen?").toLowerCase();
if (question4 === answer4) {
  userScore +=1;
  } 

const question5 = prompt("What color is a strawberry?").toLowerCase();
if (question5 === answer5) {
  userScore +=1;
  } 



// this the code to give the user its ranking
if (userScore === 5){
  userRank = ("Gold");
 } else if (userScore >= 3) {
   userRank = ("Silver");
 } else if (userScore >=1){
   userRank = ("Bronze");
 } else { 
   userRank = ("you did not get a");
 }
monique champagne
monique champagne
761 Points

Hey- I'm having the same issue- can't really figure out when its appropriate to add .toUpperCase and when its not.. I tried adding it here (a snippet of example code)

var question1 = prompt("What is the color of the ocean?");
var question2 = prompt("What is the color of they sky?")
var question3 = prompt("What color is a black cat?")

var answer1.toUpperCase() = "BLUE"
var answer2.toUpperCase() = "BLUE"
var answer3.toUpperCase() = "BLACK"

but that didnt work- this however did (along with the answers directly above this post) and im not sure why...

if (question1.toUpperCase() === answer1){
  correct += 1;
}
if (question2.toUpperCase() === answer2){
  correct += 1;
}
if (question3.toUpperCase() === answer3){
  correct += 1;
}