javascript - Operators not working? -


ok did according suggestion looks amatuerish ha.. cos repeats same thing each percentage group: css , message. wondering if there way change it? if not, ok this..

if (69 < percentdiscount && percentdiscount < 101) {

        $(this).find("#percentoff").html('&gt; 70% off');         $(this).find("#percentoff").addclass('badge70');     }      else if (49 < percentdiscount && percentdiscount < 70) {          $(this).find("#percentoff").html('&gt; 50% off');         $(this).find("#percentoff").addclass('badge50');     }      else if (29 < percentdiscount && percentdiscount < 50) {          $(this).find("#percentoff").html('&gt; 30% off');         $(this).find("#percentoff").addclass('badge30');     }       else if (19 < percentdiscount && percentdiscount < 30) {          $(this).find("#percentoff").html('&gt; 20% off');         $(this).find("#percentoff").addclass('badge30');     } 

you're checking percentdiscount that's both higher both numbers, in second if check, there no numbers left above 69. should instead (keeping exclusion logic):

if (percentdiscount > 69 && percentdiscount < 101) {         $(this).find("#percentoff").html('&gt; 70% off');     $(this).find("#percentoff").addclass('badge70'); }     else if (percentdiscount > 49 && percentdiscount < 69) {         $(this).find("#percentoff").html('&gt; 50% off');     $(this).find("#percentoff").addclass('badge50'); }     else if (percentdiscount > 29 && percentdiscount < 49) {         $(this).find("#percentoff").html('&gt; 30% off');     $(this).find("#percentoff").addclass('badge30'); } 

swap terms they're in same order have above, think you'll find it's much easier read. however, overall terms exclude 69, , 49 points specifically, i'd change logic this:

if (percentdiscount > 69) {         $(this).find("#percentoff").html('&gt; 70% off');     $(this).find("#percentoff").addclass('badge70'); }     else if (percentdiscount > 49) {         $(this).find("#percentoff").html('&gt; 50% off');     $(this).find("#percentoff").addclass('badge50'); }     else if (percentdiscount > 29) {         $(this).find("#percentoff").html('&gt; 30% off');     $(this).find("#percentoff").addclass('badge30'); } 

the first if grabs above 69, next above, 49, etc...much simpler :)


Comments

Popular posts from this blog

android - Spacing between the stars of a rating bar? -

aspxgridview - Devexpress grid - header filter does not work if column is initially hidden -

c# - How to execute a particular part of code asynchronously in a class -