+ 1
Hi why is the isInteger not working
I want to write a function to roll a dice. It has a parameter of the number of faces but when I check to make sure it's an integer, but doesn't seem to work. Thanks Graeme https://code.sololearn.com/WYIcdn2lquMr/?ref=app
3 Answers
+ 7
write only
if (Number.isInteger(inValue))
if it is true and you compare true == false it would evaluate to false
+ 3
Try to convert <inValue> argument into a number before verifying it as integer using Number.isInteger().
inValue = Number( inValue );
if( !Number.isInteger( inValue ) ) // <- notice the logical NOT operator `!`
{
// it's not an integer
}
The type of <inValue> is string, therefore it doesn't count as integer, as it was not even a numeric data.
0
Graeme Adamson
tweaked your code.
The main problem is 'input.value' is still type string.
A quick trick is to add a + symbol in front to convert it to int.
https://code.sololearn.com/WJKluCxsCRmK/?ref=app