我正在从一本书和一本代码示例中学习JavaScript,我从本书中编写它只适用于jsfiddle。我尝试过Chrome和IE,但提示不会出现。这是我的代码:
<script type="text/JavaScript">
var userNumbers = new Array();
var userInput = 0;
var arrayIndex = 0;
var message = '';
var total = 0;
while (userInput != 99) {
userInput = prompt("Enter a number, or 99 to exit", "99");
userNumbers[arrayIndex] = userInput;
arrayIndex++;
}
message += 'You entered the following:\n';
for (var i = 0; i< arrayIndex-1;i++) {
message += userNumbers[i] + '\n';
total += Number(userNumbers[i]);
}
message += 'Total:' total + '\n';
alert(message);
</script>
答案 0 :(得分:2)
你的专栏:
message += 'Total:' total + '\n';
应该是
message += 'Total:' + total + '\n';