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?

13th Jan 2023, 11:45 AM
Dr AGB Anuradha
Dr AGB Anuradha - avatar
4 Antworten
+ 1
You don't need second loop . instead of 2nd loop you need if condition like this If scores>=70 { print pass }
13th Jan 2023, 12:00 PM
A S Raghuvanshi
A S Raghuvanshi - avatar
+ 1
The number of the passed students are needed. Not whether the student is pass or not
13th Jan 2023, 12:32 PM
Dr AGB Anuradha
Dr AGB Anuradha - avatar
+ 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.
13th Jan 2023, 1:00 PM
PanicS
PanicS - avatar