Why doesn't "0" make this statement false?


#1

This code exits if user input is greater than 100 or if an empty line is entered:

let num;
do {
  num = prompt("Enter a number greater than 100?", 0);
} while (num <= 100 && num);

if 0 == false, and
num = 0,
shouldn’t an input of 0 exit the loop?


#2

Hi @LFsolar

user input will always be a string. In JS “0” is a true value while 0 is false. You could convert the input to a Number prior to it being checked.