0
if i need to scan for even number in an array function where should i do it before or after the loop
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();
+ 1
what?
+ 1
ok
0
inside the loop
0
i tried
0
show me how you tried
0
ok its public
0
the aim of my code is to do a function contains an array of 3 elements and get the greatest even number
0
how do you get array data? from prompt?
0
yes
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();
0
thanks for ur help but though i have problem
0
i try something and ill tell u the result
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();
0
thank u man u helped a lot and finally i got what i need