0

Even odd program in JavaScript using for lool

11th May 2017, 5:37 AM
chetana
chetana - avatar
3 Antworten
+ 4
Here you go, a program calculates odd and even numbers from an array. https://code.sololearn.com/W3zXTUIR3638/?ref=app
11th May 2017, 5:55 AM
Calviղ
Calviղ - avatar
+ 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 )
11th May 2017, 9:14 AM
visph
visph - avatar
+ 1
Thanks!
13th May 2017, 5:43 PM
chetana
chetana - avatar