Having trouble with 'while' loop in javascript

前端 未结 3 646
长发绾君心
长发绾君心 2021-01-28 18:55

I\'m new with javascript, and I\'m having some trouble understanding why this code doesn\'t execute:

var weight;

wight=parseInt(prompt(\"Please, enter weight\")         


        
3条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2021-01-28 19:24

    Try this

    var weight;
    
    weight=parseInt(prompt("Please, enter weight"));
    
    while (weight>0)
    { 
      if (weight>199 && weight<300)
    {
      document.write("Tax will be" + weight*5);
    }
      else 
    {
      document.write("Tax will be" + weight*10);
    }
    }
    

提交回复
热议问题