Back to Freecodecamp

Challenge 226: Passing Exam Count

curriculum/challenges/english/blocks/daily-coding-challenges-javascript/69a890af247de743333bd4cf.md

latest1.4 KB
Original Source

--description--

Given an array of student exam scores and the score needed to pass it, return the number of students that passed the exam.

--hints--

passingCount([90, 85, 75, 60, 50], 70) should return 3.

js
assert.equal(passingCount([90, 85, 75, 60, 50], 70), 3);

passingCount([100, 80, 75, 88, 72, 74, 79, 71, 60, 92], 75) should return 6.

js
assert.equal(passingCount([100, 80, 75, 88, 72, 74, 79, 71, 60, 92], 75), 6);

passingCount([79, 60, 88, 72, 74, 59, 75, 71, 80, 92], 60) should return 9.

js
assert.equal(passingCount([79, 60, 88, 72, 74, 59, 75, 71, 80, 92], 60), 9);

passingCount([76, 79, 80, 70, 71, 65, 79, 78, 59, 72], 85) should return 0.

js
assert.equal(passingCount([76, 79, 80, 70, 71, 65, 79, 78, 59, 72], 85), 0);

passingCount([84, 65, 98, 53, 58, 71, 91, 80, 92, 70, 73, 83, 86, 69, 84, 77, 72, 58, 69, 75, 66, 68, 72, 96, 90, 63, 88, 63, 80, 67], 60) should return 27.

js
assert.equal(passingCount([84, 65, 98, 53, 58, 71, 91, 80, 92, 70, 73, 83, 86, 69, 84, 77, 72, 58, 69, 75, 66, 68, 72, 96, 90, 63, 88, 63, 80, 67], 60), 27);

--seed--

--seed-contents--

js
function passingCount(scores, passingScore) {

  return scores;
}

--solutions--

js
function passingCount(scores, passingScore) {
  let count = 0;

  for (const score of scores) {
    if (score >= passingScore) {
      count++;
    }
  }

  return count;
}