Grade book : codewars javascript

front·2022년 11월 9일

kata

Complete the function so that it finds the average of the three scores passed to it and returns the letter value associated with that grade.

Numerical Score	Letter Grade
90 <= score <= 100	'A'
80 <= score < 90	'B'
70 <= score < 80	'C'
60 <= score < 70	'D'
0 <= score < 60	'F'
Tested values are all between 0 and 100. Theres is no need to check for negative values or values greater than 100.

my answer

function getGrade (s1, s2, s3) {
  var score = (s1 + s2 + s3) / 3;
  if (score <= 100 && score >= 90) {
     return 'A';
  } else if (score < 90  && score >= 80) {
     return 'B';
  } else if (score < 80 && score >= 70) {
    return 'C';
  } else if (score < 70 && score >= 60) {
    return 'D';
  } else {
    return 'F';
  }

}

best answer

function getGrade (s1, s2, s3) {
  avg = (s1+s2+s3)/3;
  if (avg < 60)  return "F";
    else if (avg < 70) return "D";
    else if (avg < 80) return "C";
    else if (avg < 90) return "B";
    else return "A";
}
profile
그냥 하기

2개의 댓글

comment-user-thumbnail
2023년 3월 23일

Energy efficiency is important when it comes to refrigerators. An energy-efficient refrigerator will save you money on your energy bills over time. Look for a refrigerator with an Energy Star rating. This will ensure you’re getting the most efficient refrigerator. https://bestsidebysiderefrigerators.com/best-side-by-side-refrigerator-for-garage/

답글 달기
comment-user-thumbnail
2023년 11월 25일

E-commerce is booming, and dropshipping provides an accessible entry into the market. With this model, you sell products without holding inventory.
learn this here now
directory
why not find out more

답글 달기