我需要一些帮助来解释这段代码。我已经改变了值,但由于某些原因,计算出的值总是上来为12HTML计算按钮
<html>
<head>
<script>
function display(x)
{
alert("The result is " + x);
}
function calculate(){
var values = new Array(5, 8, 18, 16);
var output = values[1]+values[3];
if (output >= 23){output = output/2;}
else {output = output++;}
display(output);
}
</script>
</head>
<body>
<button onclick="calculate()">Click to calculate</button>
</body>
谢谢!
是的。 8 + 16是24,所以2除以12(数组从索引'0'btw开始) –
(8 + 16)/ 2 _is_ 12. – BSMP
按预期工作。 'value [1]'(8)+'value [3]'(16)等于24.因为它高于23,所以它会除以2,得到12。你能澄清一下有什么问题吗? – Andre