I must be missing something .. not sure why my JavaScript is failing or not working
var discount = 10; var newTemp; if (discount != null) { if (discount.indexOf("%") > -1) { newTemp = discount.substring(0, 2) + '%'; } else { newTemp = discount; } } //end of outer if Above script works when discount = "10.0%" But fails when discount = 10
maynot be best way, but all I am trying to do is if discount value contains % sign then setting newTemp variable with new value. Else just keep it as is.
Any idea, why control fails when discount value is = 10