How to test a variable over several ranges of numbers

advertisements

I am a student taking JavaScript. I am still new at this and I need some help

I am trying to create a script that tells people to enter a number which will be their average, and it will tell them what letter grade they get.

{
    alert("You got an A+, excellent!")

} else if (average   && 90-94) {
    alert("You got an A, congrats!")

} else if (average  87-89) {
    alert("You got an B+, great job!")

} else if (average  83-86) {
    alert("You got a B, good!")

} else if (average  80-82) {
    alert("You got a B-, good but push for an A!")

} else if (average  77-79) {
    alert("You got an C+, good but work harder!")

} else if (average  73-76) {
    alert("You got an C, work harder!")

} else if (average  70-72) {
    alert("You got a C-, work harder!")

} else if (average  65-69) {
    alert("you got a D, so poor!")

} else if (average <65) {
    alert("F, see you next semester")

} else {
    alert("Invalid, please try again")
}

Now the problem is, I do not know how to add multiple numbers into each section. I tried the && and commas but it did not work.


You could also do something like this:

var score = parseInt(prompt("Please enter score (0 to 100)"));

switch (true) {
    case (score > 100 || score < 0):
        alert("Invalid, try again!");
        break;
    case (score >= 94):
        alert("You got an A+, excellent!");
        break;
    case (score >= 90):
        alert("You got an A, congrats!");
        break;
    case (score >= 87):
        alert("You got a B+, super!");
        break;

    // etc., etc.

    case (score >= 65):
        alert("D, so poor!");
        break;
    default:
        alert("F, see you next semester.");
}