Write a function that accepts an array of test scores as an argument then the function should return a number of scores that 80 or higher? [duplicate]

Multi tool use


Write a function that accepts an array of test scores as an argument then the function should return a number of scores that 80 or higher? [duplicate]
This question already has an answer here:
I'm still pretty new into JS but I'm having a hard time with this problem. I'm sure the answer is somewhat simple but i can't figure out what to put into the function expression after i've made my array of scores? Do i need to do a for loop?
Thanks
let array = [20,30,40,50,60,70,80,92,93,95,98,100]
function testScores(array){
}
This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.
please add the result as well. do you need all values above or just a single value, the first or the smallest, or what ever?
– Nina Scholz
4 mins ago
2 Answers
2
you can use array's filter method. please follow below definition.
function testScores(array){
return array.filter(ele=>ele>=80)
}
He/She wants the number as output.
– FullStackDeveloper
5 mins ago
btw,
testScores
is plural.– Nina Scholz
32 secs ago
testScores
function testScores(array){
return array.filter(number => number >= 80);
}
This will return an array of scores more 80 and above.
e.g
let scores = [20,30,40,50,60,70,80,92,93,95,98,100];
testScores(scores)
If you just want the count of scores more than 80 you can do
testScores(scores).length
He/She wants the number as output.
– FullStackDeveloper
5 mins ago
btw,
testScores
is plural.– Nina Scholz
22 secs ago
testScores
See generally: stackoverflow.com/questions/3010840/…
– Michael W.
9 mins ago