I made a function all by myself that calculate a student score by the percentage of the maximum possible score, no matter what the maximum score we put, it will remain the same.
It`s my first time of making a function all by myself and that feeling of really understand the material is just awesome!
let gradScore = function (sScore, totalScore = 20) {
let scorePercent = (sScore * 100) / totalScore
let scoreA = .9 * totalScore
let scoreB = .8 * totalScore
let scoreC = .7 * totalScore
let scoreD = .6 * totalScore
if (sScore < totalScore && sScore >= scoreA) {
return
CONGRATS! You got A (${scorePercent}%)
} else if (sScore < scoreA && sScore >= scoreB) {
return
Nice, you got B (${scorePercent}%)
} else if (sScore < scoreB && sScore >= scoreC) {
return
You got C (${scorePercent}%)
} else if (sScore < scoreC && sScore >= scoreD) {
return
Ahh, You got D (${scorePercent}%)
} else {
return
Not Good, you got F (${scorePercent}%). Maybe next time
}
}
let studantScore = gradScore(19)
console.log(studantScore)
p.s
I would love to hear from you if i could do it in more useful way