Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

JS: Grading System of a school Any Fix (Error== undefined)

A school has the following rules for the grading system:

// a. 45 to 50 - D
// b. 50 to 60 - C
// c. 60 to 80 - B
// d.Above 80 - A

Ask the user to enter marks, name as well as Roll No and print the corresponding grade

const school_grading_system = () => {
  let student_details = {
    name_of_student: prompt("Enter your name:"),
    roll_number_of_student: Number(prompt("Enter your Roll No: ")),
    marks_of_student: Number(prompt("Enter your marks out of 100: ")),
    percentage_obtained_student: function() {
      return ((this.marks_of_student / 100) * 100)
    }
  }
  if (this.percentage_obtained_student >= 80 && this.percentage_obtained_student < 80) {
    console.log(`${this.percentage_obtained_student}:Good Job! You have scored A Grade`)
  } else if (this.percentage_obtained_student >= 60 && this.percentage_obtained_student < 60) {
    console.log(`${this.percentage_obtained_student}: Good! You have obtained B Grade`)
  } else if (this.percentage_obtained_student >= 50 && this.percentage_obtained_student < 60) {
    console.log(`${this.percentage_obtained_student}: Good! You have obtained C Grade`)
  } else if (this.percentage_obtained_student >= 45 && this.percentage_obtained_student < 50) {
    console.log(`${this.percentage_obtained_student}: Good! You have obtained D Grade`)
  }
}

console.log(school_grading_system())

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

// Rule 1: Kinda keep it simple 
// As total marks are going to be 100 so no need for a percentage method

const school_grading_system = () => {
  let student_details = {
    name_of_student: prompt("Enter your name:"),
    roll_number_of_student: Number(prompt("Enter your Roll No: ")),
    marks_of_student: Number(prompt("Enter your marks out of 100: "))

  }
  if (student_details.marks_of_student >= 45 && student_details.marks_of_student < 50) {
    return "Grade D"
  } else if (student_details.marks_of_student >= 50 && student_details.marks_of_student < 60) {
    return "Grade C"
  } else if (student_details.marks_of_student >= 60 && student_details.marks_of_student < 80) {
    return "Grade B"
  } else if (student_details.marks_of_student >= 80 && student_details.marks_of_student <= 100) {
    return "Grade A"
  }
}
console.log(school_grading_system())


// Note: I have not displayed the name and marks stuff because I hope you are capable enough to do that so I am leaving that upon you
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading