0

Checking if a number is divisible by 2?

I'm trying to write a program that checks if a number is divisible by 2. The input needs to be a number(Obviously xD). If the input is not a number, it needs to say something along the lines of "Input is not a number. Please enter a number!". If the input is a number, it needs to display 1 of 2 things: 1. "VariableNumber is not divisible by 2. 2. VariableNumber is divisible by 2. Everything I try fail. In my last attempt, I was able to make it so it would display those 2 things, but entering letters caused it to print "(random letters) is not divisible by 2.". I manged to fix it, but then all of the sudden, everything was divisible by 2. So I need help. Here's the new code I just started. You can go about displaying the output any way you want. https://code.sololearn.com/W71keXUbAKcL/#html

6th Aug 2018, 8:30 PM
Daniel Cooper
Daniel Cooper - avatar
5 odpowiedzi
0
I know how to check for it, but how can I make it do all of the things mentioned? I just tried it again and it didn't work. It seems to ignore my code telling it to print something else if it's not a number. just says "letters is not divisible by 2".
6th Aug 2018, 8:46 PM
Daniel Cooper
Daniel Cooper - avatar
0
Thanks 「HAPPY TO HELP」 Also, long time no see xD
6th Aug 2018, 9:37 PM
Daniel Cooper
Daniel Cooper - avatar
0
One more question Why did it not work with my version? My version was pretty much the same, except I used this: if(a !== NaN) { //code to execute } or if(a !== isNaN) { //code to execute }
6th Aug 2018, 11:00 PM
Daniel Cooper
Daniel Cooper - avatar
0
But even when I used isNaN in ny version, it failed. Why? Does it have to do with the way I typed it?
7th Aug 2018, 3:37 AM
Daniel Cooper
Daniel Cooper - avatar
0
if(!isNaN(a) { // a is a number }
7th Aug 2018, 6:02 AM
Calviղ
Calviղ - avatar