0
I’m trying to separate students according to their numbers in the notebook where students grade A would be students numbering over 170, students B students numbering 160 to 169 and students C numbering 150 to 159.
I’m trying to get you back on the console like this: student Receive [170, 170, 171, 187, 191] and with alunosB and C the same. more does not appear I did like this below but only appears me Undefined and when I put in the function parameter the variable alunoA= even appears something else and only the same number independent of the variable.
var numeroCardeneta = [170, 159, 151, 187, 156, 191, 165, 154, 167, 169, 171, 170, 160]
var alunosA = []
var alunosB = []
var alunosC = []
function classes(numeroCardeneta) {
for (var i = 0; i < numeroCardeneta.length; i++){
if (numeroCardeneta[i] >= 150 && numeroCardeneta[i] <=159){
alunosNotaC.push(numeroCardeneta[i])
return alunosNotaC
} else if (numeroCardeneta[i] >= 160 && numeroCardeneta[i] <= 169){
alunosNotaB.push(numeroCardeneta[i])
return alunosNotaB
} else if (numeroCardeneta[i] >= 170){
alunosNotaA.push(numeroCardeneta[i])
return alunosNotaA
}
}
}
console.log(classes(alunosNotaA))
Read your own code, what’s that code for
return
within eachif
? You are practically forcing the cycle to end at the first value, remove all thesereturn
, besides you are interned over the array you pass as parameter, which means that if it is empty that is the case of the example, nothing will work. If you need to iterate onnumeroCardeneta
you don’t passalunosNotaA
as a parameter– Leo Letto
ok thanks for the advice, and I started studying javascript a little while ago. I will look no further wrong on this issue XD
– alexandre