to a number at the return?
Near the prompt, I can't put "+" because after that 0 is showing as an empty string. The task is: Force the user to enter a number from the keyboard (not a string and not NaN).
function getNumber() {
let num;
do {
num = prompt("Enter number", '');
} while (!isFinite(num) || num === "");
if (num === null || num === "") return null;
console.log("Number! Yes!");
return +num;
;
}
getNumber();
parseInt tries to convert the provided argument to an string, indeed the variable num is of type string, but what you have to look after is the returned value of the function getNumber
You can also learn about the function Number, Google it and see how it works
Обсуждают сегодня