---
id: 6626b8dcf5057f896f948440
title: Step 4
challengeType: 1
dashedName: step-4
---

# --description--

Now that the teacher has all of the information they need, they want to be able to message the student with the results. 

Complete the `studentMsg` function with `totalScores` and `studentScore` for parameters. The function should return a string representing a message to the student.

If the student passed the course, the string should follow this format:

```md
Class average: average-goes-here. Your grade: grade-goes-here. You passed the course.
```

If the student failed the course, the string should follow this format:

```md
Class average: average-goes-here. Your grade: grade-goes-here. You failed the course.
```

Replace `average-goes-here` with the average of the total scores. 
Replace `grade-goes-here` with the student's grade.

**Tips**

- Use the `getAverage` function to get the class average.
- Use the `getGrade` function to get the student's grade.
- Use string concatenation (`+`) to build the message. 
- Be careful with the punctuation and spaces in the message. 

# --hints--

`studentMsg([92, 88, 12, 77, 57, 100, 67, 38, 97, 89], 37)` should return the following message: `"Class average: 71.7. Your grade: F. You failed the course."`.

```js
assert.strictEqual(studentMsg([92, 88, 12, 77, 57, 100, 67, 38, 97, 89], 37), "Class average: 71.7. Your grade: F. You failed the course.");
```

`studentMsg([56, 23, 89, 42, 75, 11, 68, 34, 91, 19], 100)` should return the following message: `"Class average: 50.8. Your grade: A++. You passed the course."`.

```js
assert.strictEqual(studentMsg([56, 23, 89, 42, 75, 11, 68, 34, 91, 19], 100), "Class average: 50.8. Your grade: A++. You passed the course.");
```

Your `studentMsg` function should return the correct message based on the student's score and the class average.

```js
assert.strictEqual(studentMsg([33, 44, 55, 66, 77, 88, 99, 100], 92), "Class average: 70.25. Your grade: A. You passed the course.");
assert.strictEqual(studentMsg([33, 44, 55, 66, 77, 88, 99, 100], 57), "Class average: 70.25. Your grade: F. You failed the course.");
```

# --seed--

## --seed-contents--

```js
function getAverage(scores) {
  let sum = 0;

  for (const score of scores) {
    sum += score;
  }

  return sum / scores.length;
}

function getGrade(score) {
  if (score === 100) {
    return "A++";
  } else if (score >= 90) {
    return "A";
  } else if (score >= 80) {
    return "B";
  } else if (score >= 70) {
    return "C";
  } else if (score >= 60) {
    return "D";
  } else {
    return "F";
  }
}

function hasPassingGrade(score) {
  return getGrade(score) !== "F";
}

--fcc-editable-region--
function studentMsg(totalScores, studentScore) {

}
console.log(studentMsg([92, 88, 12, 77, 57, 100, 67, 38, 97, 89], 37));
--fcc-editable-region--

```


# --solutions--

```js
function getAverage(scores) {
  let sum = 0;

  for (const score of scores) {
    sum += score;
  }

  return sum / scores.length;
}

function getGrade(score) {
  if (score === 100) {
    return "A++";
  } else if (score >= 90) {
    return "A";
  } else if (score >= 80) {
    return "B";
  } else if (score >= 70) {
    return "C";
  } else if (score >= 60) {
    return "D";
  } else {
    return "F";
  }
}

function hasPassingGrade(score) {
  return getGrade(score) !== "F";
}

function studentMsg(totalScores, studentScore) {
  let average = getAverage(totalScores);
  let grade = getGrade(studentScore);

  return `Class average: ${average}. Your grade: ${grade}. You ${
    hasPassingGrade(studentScore) ? "passed" : "failed"
  } the course.`;
}

```
