0
A help needed?
Students need to score at least 70 points to pass an exam. The given program declares an array with results. Write a program to count and output to the console the number of students who pass the exam. let scores = [68,95,54,84,77,75,63,74,69,80,71,63] //your code goes here for(let x=0; x<=scores.length; x++){ for(let y=0; scores[x]>=70; y++){ console.log(y); } } Why this above code is incorrect?
4 Respostas
+ 1
You don't need second loop . instead of 2nd loop you need if condition like this
If scores>=70 {
print pass
}
+ 1
The number of the passed students are needed. Not whether the student is pass or not
+ 1
Dr AGB Anuradha you also need some counter outside of loop, not additional loop, then use ASR example but increase counter inside if condition(and check for scores[x] not just scores, scores is full array)
Then outside of loop print total number of passed students
Your code log y if x is >= 70, so
Numbers:
1,4,5,6,8,10,11
What represent indexes of score, what passed test.(Y start from 0 so it can be index)
So code will work if you would log scores[x] but it is better performance if you just add if condition not to make another loop what just check same thing what if does.