【发布时间】:2011-12-05 22:13:06
【问题描述】:
我在写的JavaScript 中遇到问题。该脚本假设提示用户输入重量,从 0 到 126,然后弹出一个警告框,说明他们所处的重量。
weight class from to
-------------------------------
Fly 0 112
SuperFly 112 115
Bantam 115 118
SuperBantam 118 122
Feather 122 126
<script type="text/javascript">
var weight = parseInt(prompt("What is your weight?"));
if (weight > 126) {
alert('Please enter a weight lighter than 126');
}
document.writeln('<br/>');
var wArray = String ([fly,superfly,bantam,superbantam,feather]);
function recruit() {
if (0 < weight < 112){
document.writeln('You are in' + wArray[0] +'class!');
}
if (112 < weight < 115){
document.writeln('You are in' + wArray[1] +'class!');
}
if (115 < weight < 118){
document.writeln('You are in' + wArray[2] +'class!');
}
if (118 < weight < 122){
document.writeln('You are in' + wArray[3] +'class!');
}
if (122 < weight 126){
document.writeln('Your weight class is' + wArray[4]);
}
</script>
【问题讨论】:
-
请注意,您的函数缺少一个结束
}。适当且一致的缩进(我已应用于您的问题)将帮助您注意到这样的事情。
标签: javascript logic helper