let checkOrFold = undefined
while(checkOrFold != 'check' && checkOrFold != 'fold'){
let checkOrFold = prompt(`check or fold?`);
console.log(checkOrFold != 'check' && checkOrFold != 'fold')
}
console.log('finish') here
even the console is logging false but prompt keeps popping up. What could be wrong?
Tried debugging. When ‘check’ or ‘fold’ is typed, console.log should show finish.
3
Answers
try matching the response till you get either check or fold as a response
while(checkOrFold = ‘check’ || checkOrFold = ‘fold’)
You’re declaring another variable with the same name in the while loop. Remove the
let
from within the while loop and you should get what you’re looking for.You probably want to prompt outside the while loop once, so
checkOrFold
has a chance to receive an input. You also, by accident, setup a separate block scoped variablecheckOrFold
inside the loop, you need to use the samecheckOrFold
for the whole portion of code to work.Solution: