+ 2
I need know what's error, I help me please..
var arr = ["Louis", "Martha", 20, 35, "Jhon", 70]; function comprobar(){ switch(arr){ case arr[0]: if(isNaN(arr[0])){ alert(arr[0] + " No es un nunero"); } else{ alert("Es un nunero"); } break; case arr[2]: if(isNaN(arr[2])){ alert(arr[2] + " Es numero"); } else{ alert("No es un nunero"); } break; } } comprobar();
3 Respuestas
+ 4
If you want to do iteration to check for each value of the array, you should use for instead of switch statement. Switch cannot do iteration, only for checking a value.
Try this:
var arr = ["Louis", "Martha", 20, 35, "Jhon", 70];
function comprobar(){
for(var i=0;i<arr.length;i++) {
if(isNaN(arr[i])){
alert(arr[i] + " No es un nunero");
}
else{
alert(arr[i] + " Es un nunero");
}
}
}
comprobar();
https://code.sololearn.com/W19vbD5REESy/?ref=app
+ 5
you compare an array with its elements, arr is not equal to arr[0] and is not equal to arr[2], so nothing is output
+ 2
thanks friend for help me