SHARE
TWEET

Untitled

a guest Jul 15th, 2019 70 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // students score, total possible score
  2. // 15/20 -> You got a C (75%)!
  3. // A 90-100, B 80-89, C 70-79, D 60-69, F 0-59
  4.  
  5. let gradeCalc = function (score, totalScore) {
  6.     let percent = (score / totalScore) * 100
  7.     let letterGrade = ' '
  8.  
  9.     if (percent >= 90) {
  10.             letterGrade = 'A'
  11.     } else if (percent >= 80) {
  12.         letterGrade = 'B'
  13.     } else if (percent >= 70) {
  14.         letterGrade = 'C'
  15.     } else if (percent >= 60) {
  16.         letterGrade = 'D'
  17.     } else {
  18.             letterGrade = 'F'
  19.     }
  20.  
  21.     return `You got a ${letterGrade} (${percent}%)!`
  22. }
  23.  
  24. let result = gradeCalc(15, 20)
  25. console.log(result)
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top