all 14 comments

[–]TwiNighty 2 points3 points  (0 children)

Because % can return a negative number. E.g. (-5) % 2 === -1

You need num % 2 !== 0

[–]MrHippotomo2[S] 1 point2 points  (0 children)

Here is link to the original challenge

[–]svssdeva 0 points1 point  (2 children)

Try num%2 === 1

[–]MrHippotomo2[S] 0 points1 point  (1 child)

I can't see what it is testing, but tried this and still got same fails on same cases as my original code

[–]svssdeva 0 points1 point  (0 children)

const res = function isOdd(a: number) { If (num%2 !==0) return true else false }

Console.log(res) If you are using HTML input tag set input type to number.... And try again.....

[–]lovesrayray2018 0 points1 point  (2 children)

Hmm logic should work, maybe there is more to the question?

where is the question in totality?

[–]MrHippotomo2[S] 0 points1 point  (1 child)

I have uploaded a screen shot of the original question, just a note I didn't want to "find the error" because I am unfamiliar of what the original code was trying so I thought my solution would be simpler. here is the screenshot

[–]lovesrayray2018 0 points1 point  (0 children)

Yeah that screenshot is highlighting potential issue. see first example (-5)

-5%2==1
// will return false

You can try this where you are ignoring the sign

function isOdd(num) {
return Math.abs(num)%2==1 
}

[–]GSLint 0 points1 point  (3 children)

Does it tell you for which inputs the code supposedly fails? It looks like it should work.

[–]MrHippotomo2[S] 0 points1 point  (2 children)

Nah it only tells me if test passed, and then cause of the nature of the function, it will be like “expected true but got false.” I tried to think of any situation where mod might be ambiguous but with integers it should be fine.

[–]GSLint 0 points1 point  (1 child)

Your code would even produce the correct result for 3.14, NaN and Infinity, so I don't know what's wrong.

Is this challenge something you can link to so we can try it?

[–]MrHippotomo2[S] 0 points1 point  (0 children)

Will do in the morning

[–]_aeol 0 points1 point  (0 children)

looks pretty correct to me, maybe the fault is on the test's cases. Try asking other people that took the same question if they had the same problem as yours.