Skip to content

Instantly share code, notes, and snippets.

@sethmwebi
Created July 1, 2024 14:16
Show Gist options
  • Save sethmwebi/ec3fc784ecf948cf113ba33a4f8af8e7 to your computer and use it in GitHub Desktop.
Save sethmwebi/ec3fc784ecf948cf113ba33a4f8af8e7 to your computer and use it in GitHub Desktop.
const r1 = require("readline").createInterface({
input: process.stdin,
output: process.stdout,
});
function awardGrades(score) {
if (score > 79) {
return "A";
} else if (score >= 60 && score <= 79) {
return "B";
} else if (score >= 50 && score <= 59) {
return "C";
} else if (score >= 40 && score <= 49) {
return "D";
} else {
return "E";
}
}
r1.question("Enter student marks: ", function (input) {
const mark = Number(input);
if (isNaN(mark) || mark > 100 || mark < 0) {
console.log("The marks you entered is not correct");
} else {
let grade = awardGrades(mark);
console.log("The grade is " + grade);
}
r1.close();
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment