mardi 25 juillet 2017

Shortest way to compare your score to three ranges in jQuery

I have the following code:

function display_message() {
    var low = data.result[0].max; //returns 30
    var medium = data.result[1].max; // returns 60
    var high = data.result[2].max; // returns 100

    // mypoints are 67 for example
    if(mypoints > low) {
        if(mypoints > medium) {
            alert('You got a high score');
        } else {
            alert('You got a medium score');
        }
    } else {
        alert('You got a low score');
    }
}

This code works fine. I compare my average score to the standard low / medium / high score.

Low score: 0-30 points Medium score: 31-60 points High score: 61-100 points

My question though is how to make my code a bit prettier? I am not sure if the code is considered as clear and efficient.

Any opinions would be much appreciated, thank you

Aucun commentaire:

Enregistrer un commentaire