javascript - How to put a if condition so that it matches these two conditions? -


i have 2 variables sellprice , buyprice , need check these 2 conditions before procedding further .

  1. difference between buyprice - sellprice should not less 1 .
  2. difference between sellprice - buyprice should not greater 6 .

i able achive first 1 , not both @ same time

<!doctype html> <html> <head> <script> function verify() {    var sellprice = parsefloat(150); var buyprice = parsefloat(148);  if(buyprice -sellprice>=-1.00) {  alert('ok'); }  else { alert('false'); }  } </script> </head> <body>    <button type="button" onclick="verify()">verify</button>  </body> </html>  

require advice , if nything better can done achieve .

you can add many conditions , (&&) , or (||)

function verify() {      var sellprice = parsefloat(150);     var buyprice  = parsefloat(148);      var total = buyprice - sellprice;      if (total >= 1 && total <= 6) {         alert('ok');     } else {        alert('false');     }  } 

if read out, makes sense, total more or equal 1, , less or equal 6


Comments

Popular posts from this blog

how to proxy from https to http with lighttpd -

android - Automated my builds -

python - Flask migration error -