Home > database >  Type Error : not iterable Array Function (Beginner)
Type Error : not iterable Array Function (Beginner)

Time:12-09

 let grades=[4,73,67,38,33]
 
 function gradingStudents(grades) {
  for (const i of grades) {
    if (i >= 38 && i % 5 == 3) {
      return i   2;}
    else if (i >= 38 && i % 5 == 4) {
      return i   1;}
    return i;
    
  }
}
console.log(gradingStudents())

I am trying to log the results but the function is not working I know I missed something, I am a beginner can you tell me what I am doing wrong.

I tried what could but I dont understand

CodePudding user response:

Your functions expects an argument.

While calling function, you are not passing any argument.

Be sure to call your function with argument. Such as,

console.log(gradingStudents(grades))

CodePudding user response:

im a beginner to i know this is not the best way to display the result of GrandingStudents Function but it works i think this is not a good idea to make a return in a loop. the loop will break at the first iteration

My Solution

  • Related