javascript - Shortest way to compare your score to three ranges in jQuery -


i have 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 67 example     if(mypoints > low) {         if(mypoints > medium) {             alert('you got high score');         } else {             alert('you got medium score');         }     } else {         alert('you got low score');     } } 

this code works fine. compare average score standard low / medium / high score.

low score: 0-30 points
medium score: 31-60 points
high score: 61-100 points

my question though how make code bit prettier? not sure if code considered clear , efficient.

any opinions appreciated, thank you

there no need if else low, check smallest highest.

if (mypoints <= low) {   //low msg } else if (mypoints <= medium) {   //medium msg } else {   //high msg } 

or can go opposite direction , check highest first greater than


Comments

Popular posts from this blog

html - How to set bootstrap input responsive width? -

javascript - Highchart x and y axes data from json -

javascript - Get js console.log as python variable in QWebView pyqt -