It fails for "1.0" because the number is a floating type number and the task requires you to only accept integers. Even though the number has no fractional part, it is still a floating point number. You need to make your code so that it only accepts integers and no floating point numbers and will return "NaN" for the floats. Description states It should make the conversion if the given string only contains a single integer value
It fails for "0x10" because your code automatically complier the number from base 10 (decimal) to base 16 (hexadecimal). You need to make your code return "NaN" for bases other than decimal. Description states It should assume that all numbers are not signed and written in base 10
If you're lazy, you can just make special cases for them using an if statement to filter them out :P.
Hi, I would like to ask, what is right solution with last test case, I can't get it right even if output is 16.5 (and test case is "16.5") .
What am I doing wrong, or what I get wrong from description? : )
Oh, thank you! I get it now, I was also thinking that there could be some max range for int. values, but this is not the case :).
I have to try it again : )
It fails when x = "1.0" and when x = "0x10"
It fails for "1.0" because the number is a floating type number and the task requires you to only accept integers. Even though the number has no fractional part, it is still a floating point number. You need to make your code so that it only accepts integers and no floating point numbers and will return "NaN" for the floats. Description states
It should make the conversion if the given string only contains a single integer value
It fails for "0x10" because your code automatically complier the number from base 10 (decimal) to base 16 (hexadecimal). You need to make your code return "NaN" for bases other than decimal. Description states
It should assume that all numbers are not signed and written in base 10
If you're lazy, you can just make special cases for them using an if statement to filter them out :P.
function myParseInt(IsItAInt) {
if(isNaN(IsItAInt) || (IsItAInt % 1)){
var x = "NaN";
console.log(x);
return x;
}
else{
var number = +IsItAInt;
console.log(number);
return number;
}
}
Post your code down below ^^
Still having something wrong I do not have a clue what it is :D Please can someone help? :)
Oh, I figure it out, it shoud take only integers, I missed first thousand times :D
Hi, I would like to ask, what is right solution with last test case, I can't get it right even if output is 16.5 (and test case is "16.5") .
What am I doing wrong, or what I get wrong from description? : )