Closed ghost closed 4 years ago
The problem I wish to report is contained within the following code, which is somewhere about halfway down the page.
function promptNumber(question) { let result = Number(prompt(question)); if (Number.isNaN(result)) return null; else return result; }
Number.isNaN("anyString") returns false, which defeats the purpose of this line.
Number.isNaN("anyString")
The only way this works is to do something along the lines of if(typeof result != 'number') { return null } else { return result; }
if(typeof result != 'number') { return null } else { return result; }
Because result holds the return value from Number, the value passed to Number.isNaN will never be a string.
result
Number
Number.isNaN
The problem I wish to report is contained within the following code, which is somewhere about halfway down the page.
function promptNumber(question) { let result = Number(prompt(question)); if (Number.isNaN(result)) return null; else return result; }
Number.isNaN("anyString")
returns false, which defeats the purpose of this line.The only way this works is to do something along the lines of
if(typeof result != 'number') { return null } else { return result; }