0

if i need to scan for even number in an array function where should i do it before or after the loop

25th Mar 2017, 1:17 AM
jab
jab - avatar
15 Respuestas
+ 1
function biggestEven(){ var a = new Array(3); var max =0; for (var i=0;i<a.length;i++){ a[i] = prompt ("", 1) if(i === 0){ max = a[i] % 2 == 0? a[i]:0; } else if (a[i]>max && a[i]%2==0){ max =a[i] } } alert (max); } biggestEven();
25th Mar 2017, 2:12 AM
Yaroslav Pieskov
Yaroslav Pieskov - avatar
+ 1
what?
25th Mar 2017, 2:20 AM
Yaroslav Pieskov
Yaroslav Pieskov - avatar
+ 1
ok
25th Mar 2017, 2:23 AM
Yaroslav Pieskov
Yaroslav Pieskov - avatar
0
inside the loop
25th Mar 2017, 1:26 AM
Yaroslav Pieskov
Yaroslav Pieskov - avatar
0
i tried
25th Mar 2017, 1:47 AM
jab
jab - avatar
0
show me how you tried
25th Mar 2017, 1:51 AM
Yaroslav Pieskov
Yaroslav Pieskov - avatar
0
ok its public
25th Mar 2017, 1:54 AM
jab
jab - avatar
0
the aim of my code is to do a function contains an array of 3 elements and get the greatest even number
25th Mar 2017, 1:55 AM
jab
jab - avatar
0
how do you get array data? from prompt?
25th Mar 2017, 1:58 AM
Yaroslav Pieskov
Yaroslav Pieskov - avatar
0
yes
25th Mar 2017, 1:58 AM
jab
jab - avatar
0
function biggestEven(){ var anArray = new Array(3); var biggestevennum =0; for (var i=0;i<anArray.length;i++){ if(biggestevennum >anArray && (biggestevennum %2==0)){ var biggestevennum = anArray[i] ;} document.write(biggestevennum); anArray[i]=parseFloat(window.prompt("")); } window.alert(anArray); } biggestEven();
25th Mar 2017, 1:59 AM
jab
jab - avatar
0
thanks for ur help but though i have problem
25th Mar 2017, 2:20 AM
jab
jab - avatar
0
i try something and ill tell u the result
25th Mar 2017, 2:22 AM
jab
jab - avatar
0
function biggestEven(){ var a = new Array(3); var max =0; for (var i=0;i<a.length;i++){ a[i] = parseFloat(prompt ("", 1)); if (a[i]>max && a[i]%2==0){ max =a[i]; } } alert (a); document.write(max) } biggestEven();
25th Mar 2017, 3:26 AM
jab
jab - avatar
0
thank u man u helped a lot and finally i got what i need
25th Mar 2017, 3:26 AM
jab
jab - avatar