有人能找到我的功能不起作用的原因。
function iMenu() {
var Isotope = prompt('Enter the name of the Isotope');
var HalfLife = prompt('Enter the Half-Life');
var Quantity = prompt('Enter the Quantity');
var Timescale = prompt('Enter the Timescale');
var Count = 0;
var Period = 0;
While(Quantity < 1); {
Quantity = (Quantity / 2);
Count = (Count + 1);
}
Period = (HalfLife * Count);
alert('The decay period for + Quantity + of + Isotope + is + period + + Timescale +');
}
我还是JavaScript的初学者
答案 0 :(得分:1)
你的while循环在条件和左括号之间不应该有分号。另外,不要大写。
替换:
While (Quantity < 1);
{
Quantity = (Quantity / 2);
Count = (Count + 1);
}
使用:
while (Quantity < 1){
Quantity = (Quantity / 2);
Count = (Count + 1);
}
作为一个有用的提示,你可以使用速记,所以你的while循环看起来像这样:
while (Quantity < 1){
Quantity /= 2;
Count += 1;
}
您的提醒应如下所示:
alert('The decay period for ' + Quantity + ' of ' + Isotope + ' is ' + Period + ', ' + Timescale);
答案 1 :(得分:0)
while循环中没有分号:
while(Quantity < 1) {
Quantity = (Quantity / 2);
Count = (Count + 1);
}
并正确地连接你的字符串,如下所示:
alert('The decay period for ' + Quantity + ' of ' + Isotope + ' is ' + Period + ', ' + Timescale);