-1

I understand we need to use toUpperCase, but I wasn't sure where to put it. I would like the word "toyota" to be acceptable whether it's uppercase or lowercase.

let correctGuess = false;
let car = "toyota";
let guess = prompt ('guess the car');

if (guess === car){
  correctGuess = true;
}

if (correctGuess === true){
  console.log ('correct');
}
  else {
    console.log('incorrect')
}
Parham
  • 214
  • 3
  • 12
  • 1
    `if (guess.toLowerCase()===car) {`.. I used lower case since your car (`toyota`) is listed in lower case, if you want to use uppercase you'll need to `let car="TOYOTA";` instead – Rudu Aug 18 '20 at 00:44

2 Answers2

0

Convert both of them to either uppercase or lowercase and compare.

Example:

if(guess.toLowerCase() === car.toLowerCase()) {
    // your logic
}

Although you have already defined car as lowercase so you don't really need to convert it to lowercase.

Rohit Kashyap
  • 1,553
  • 1
  • 10
  • 16
0

Change

if (guess === car){
  correctGuess = true;
}

To


if (guess.toUpperCase() === car.toUpperCase()){
  correctGuess = true;
}


Kind of redundant but it gets useful if the car variable itself was taken from a user input.

You can also make both .toLowerCase to get the same result, literally no difference