0
Even odd program in JavaScript using for lool
3 Antworten
+ 4
Here you go, a program calculates odd and even numbers from an array.
https://code.sololearn.com/W3zXTUIR3638/?ref=app
+ 4
var n = [ ]
var c = int(input('Enter how many number to test?')) || 0;
for (var i=0; i<c; i++) {
n.push(int(input('Number?')) || 0);
if (n[n.length-1]&1)
alert(n+' is an even number');
else
alert(n+' is an odd number');
}
... instead to direct convert the user entry to an integer ( or zero if not a number ), you can improve it by handling the "cancel" case of the input() return ^^
And obviously, inside the 'for' loop, you'll have to do the treatment you want ( maybe not just display if odd or even :P )
+ 1
Thanks!