Loops in ECMAScript 6: Score 70+ ! | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 2

Loops in ECMAScript 6: Score 70+ !

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. *Use a forā€¦of loop to iterate through the array. https://code.sololearn.com/cqFTmH05o4Ng/?ref=app https://code.sololearn.com/cZAe4Evoq4Sp/?ref=app Please help.

14th Feb 2022, 3:11 AM
TahitišŸŒCastillo
TahitišŸŒCastillo - avatar
8 Answers
+ 4
You can declare another variable to count the students who have higher marks than 70 and print it outside loop.
14th Feb 2022, 3:44 AM
Simba
Simba - avatar
+ 3
count is a random name of a variable rather than a keyword. For that, you can use any name you want. This is the common way to solve a challenge something like that var Tahiti = 0 for() if() Tahiti++ console.log(Tahiti)
14th Feb 2022, 5:07 AM
Simba
Simba - avatar
+ 2
TahitišŸ·Castillo 2nd code is little bit right but you are increasing scores not counting number of students. var count = 0; for (let p of scores) { if (p>=70){ count++; } } console.log (count);
14th Feb 2022, 3:48 AM
AĶ¢J
AĶ¢J - avatar
+ 1
Ok. Thank you Simba . I will try that.
14th Feb 2022, 3:45 AM
TahitišŸŒCastillo
TahitišŸŒCastillo - avatar
+ 1
AĶ¢J Thank you for pointing that out. It makes sense to me now. Iā€™m not making excuses, but the tutorials preceding these Code Coaches do not make it clear how to solve these. Thanks again.
14th Feb 2022, 4:02 AM
TahitišŸŒCastillo
TahitišŸŒCastillo - avatar
+ 1
TahitišŸ·Castillo Yes there is less information but not very less. Check this statement "count number of students who pass with 70 points" So simple you have to count if score >= 70
14th Feb 2022, 4:32 AM
AĶ¢J
AĶ¢J - avatar
+ 1
Thank you Simba for that very helpful explanation!
14th Feb 2022, 4:56 PM
TahitišŸŒCastillo
TahitišŸŒCastillo - avatar
0
AĶ¢J Yes but I was referring to the use of the count keyword and variable, which was not covered in the lesson prior to the Code Coach. Iā€™m not sure it was even covered in earlier lessons.
14th Feb 2022, 4:36 AM
TahitišŸŒCastillo
TahitišŸŒCastillo - avatar