我正在从一本书中学习 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>