Javascript Can';我的函数似乎无法正常工作
有人能找到我的功能不起作用的原因吗Javascript Can';我的函数似乎无法正常工作,javascript,Javascript,有人能找到我的功能不起作用的原因吗 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');
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 +');
}
函数iMenu(){
var同位素=提示(“输入同位素名称”);
var HalfLife=提示(“输入半衰期”);
变量数量=提示(“输入数量”);
var Timescale=提示(“输入时间刻度”);
var计数=0;
var周期=0;
而(数量<1){
数量=(数量/2);
计数=(计数+1);
}
期间=(半衰期*计数);
警报(“同位素+的+数量+的衰变期为+周期++时间刻度+”);
}
我仍然是JavaScript的初学者,while循环的条件和开始括号之间不应该有分号。同时,不要在这段时间内使用大写字母 替换:
While (Quantity < 1);
{
Quantity = (Quantity / 2);
Count = (Count + 1);
}
while循环中没有分号:
while(Quantity < 1) {
Quantity = (Quantity / 2);
Count = (Count + 1);
}
删除该文件;在while语句末尾,JavaScript区分大小写<代码>while!==而有两种情况会导致脚本无法工作或返回错误的值,其中包括一个额外的分号以及看起来不正确的连接。当你工作时,看看你的控制台,它会为你指明正确的方向。在我输入一个时间刻度字符串后,什么也不会发生。我试图让警报框显示“同位素(数量)的衰变周期是(周期)(时间尺度)”JSLint或者是你的朋友。数量是一个字符串
while (Quantity < 1){
Quantity /= 2;
Count += 1;
}
alert('The decay period for ' + Quantity + ' of ' + Isotope + ' is ' + Period + ', ' + Timescale);
while(Quantity < 1) {
Quantity = (Quantity / 2);
Count = (Count + 1);
}
alert('The decay period for ' + Quantity + ' of ' + Isotope + ' is ' + Period + ', ' + Timescale);