while (wight>0);
分号有效地使循环:当怀特大于0时,什么都不做。这迫使一个无限循环,这就是为什么其他代码不能执行。
另外,'wight'是而不是与'weight'相同。这是另一个错误。
此外,如果更改了该行对while (weight > 0)
,你仍然有一个无限循环,因为再执行不改变“重”的代码 - 因而,它会总是大于0(除非号在提示符处输入小于0,在这种情况下根本不会执行)。
你想要的是:
var weight;
weight=parseInt(prompt("Please, enter weight")); // Missing parenthesis
// Those two lines can be combined:
//var weight = parseInt(prompt("Please, enter weight"));
while(weight>0)
{
if (weight>199 && weight<300)// REMOVE semicolon - has same effect - 'do nothing'
{
document.write("Tax will be" + weight*5);
// above string probably needs to have a space at the end:
// "Tax will be " - to avoid be5 (word smashed together with number)
// Same applies below
}
else
{
document.write("Tax will be" + weight*10);
}
}
即语法正确。您仍然需要更改while条件,或者更改该循环内的“weight”,以避免无限循环。
您在一段时间后,有一个分号。去掉它。 –
你也在'weight'和'wight'之间交替。 –
所有的答案都是正确的,你也可以通过检查控制台在萤火虫找到你自己 –