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

networking - Vagrant-provisioned VirtualBox VM is not reachable from Ubuntu host -

c# - ASP.NET Core - There is already an object named 'AspNetRoles' in the database -

ruby on rails - ArgumentError: Missing host to link to! Please provide the :host parameter, set default_url_options[:host], or set :only_path to true -