Super Confused with the Loops and Functions in ES6 Practice Problem | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Super Confused with the Loops and Functions in ES6 Practice Problem

Loops in ECMAScript 6 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 I understand how to use a for...of loop, but I can't figure out how to get an incremental to not loop through the array, so it doesn't give me a bunch of 1s and 0s. Would love some help on this.

27th Mar 2021, 8:03 AM
Arthur Laffer
8 Answers
27th Mar 2021, 8:57 AM
Avinesh
Avinesh - avatar
+ 2
I can't access the code, but I assume it would be something like: let scores = [68,95,54,84,77,75,63,74,69,80,71,63]; let count = 0; for(let i = 0; i < scores.length; i++){ if(scores[i] >= 70){ count++; } } console.log(count);
27th Mar 2021, 8:47 AM
Bahhaⵣ
Bahhaⵣ - avatar
0
I will try to help if you will share your code bit link here for a review https://www.sololearn.com/post/75089/?ref=app
27th Mar 2021, 8:44 AM
Ipang
0
Avinesh can you explain your code? i really need it to undestand more of your code please
17th Jul 2021, 6:29 AM
Vincent Tok
Vincent Tok - avatar
0
let scores = [68,95,54,84,77,75,63,74,69,80,71,63] let count = 7; //your code goes here if(scores>=70){ for(let count of scores){ } }; console.log(count); well I don't know honestly how this could work but it is succesfull to created expected output please someone who can create a better code to solve the problem! i'm sorry for my bad english and my code I'm still learning(beginner)
17th Jul 2021, 6:47 AM
Vincent Tok
Vincent Tok - avatar
0
code from Avinesh let scores = [68,95,54,84,77,75,63,74,69,80,71,63] let count = 0; let newArr = scores.filter(scores =>{ if(scores >= 70){ count++; return scores } }); console.log(count); this code also create the expected output but you won't use for_of loop. You will only use if statement and give addition to count then you can return scores and return it to console. sorry if my explanation is hard to get but hopelly this will help you(at least I tried)
17th Jul 2021, 6:59 AM
Vincent Tok
Vincent Tok - avatar
0
https://www.sololearn.com/coach/967?ref=app Mine is working well with for loop
22nd Jul 2021, 9:44 AM
jackie _A
0
my solution using "for of" loop: let scores = [68,95,54,84,77,75,63,74,69,80,71,63] //your code goes here let pass =0; for(let val of scores) { if (val >= 70) { pass ++; } } console.log(pass);
5th Sep 2021, 10:58 AM
Cristina
Cristina - avatar