+ 1
Why does this function come out as NaN?
Don't worry, the function itself has little TypeScript in it. I'm making a function that adds 2 numbers together, if the parameters aren't numbers, it converts them to numbers. I tried using isNaN() but it still isn't returning a value. Line 48. https://code.sololearn.com/WGdV8Fhu7yjs/?ref=app
5 Respostas
+ 2
Well, the first argument you passed to it was "one". How was that supposed to pass the `isNaN` check?
+ 2
on line 50 you are converting "one" to int so it will print NaN because "one" cannot be converted to integer..
If your string was something "1one" then certainly it would extract 1 from the string and convert it to int..
+ 1
Which one, the `add` function or `add2`?
I think both are working as they should, what were your expectation?
0
Ipang I said line 48, so add2(). I was expecting it to convert any string to a number and add them. Instead it returns NaN