我有一个令人沮丧的时间试图让这个工作,Chrome一直显示一个未捕获的语法错误,但作为javascript的初学者,我不知道在哪里看.任何帮助或指示将不胜感激
function details(user) {
var fuel = prompt("Would you prefer petrol or diesel?");
var passengers = prompt("How many passengers will there be?");
var aircon = prompt("Do you require air-conditioning?");
var transmission = prompt("Do you want a Manual, Semi-Automatic or Automatic Transmission?");
var hire = prompt("How long would you like to hire a vehicle for? (Day Hire, Weekend Hire or Weekly Hire)");
if (fuel == "petrol" && passengers == "2" && aircon = "yes" && transmission == "semi-automatic") {
result = …Run Code Online (Sandbox Code Playgroud) 我正在尝试使用随机生成数字的数组创建一个简单的平均值计算器.我认为代码非常可靠,但我正在返回此错误:
Notice: Undefined offset: 10 in ../average/averageresults.php on line 31
Run Code Online (Sandbox Code Playgroud)
第31行:
for ($i=0; $i<=10; $i++) { echo $array[$i]."<br />"; }
Run Code Online (Sandbox Code Playgroud)
其余代码如下:
<?php
$array = array();
$array[]=rand(1, 99);
$array[]=rand(1, 99);
$array[]=rand(1, 99);
$array[]=rand(1, 99);
$array[]=rand(1, 99);
$array[]=rand(1, 99);
$array[]=rand(1, 99);
$array[]=rand(1, 99);
$array[]=rand(1, 99);
$array[]=rand(1, 99);
$i=0;
$sum = array_sum($array);
$count = count($array);
$avg = $sum/$count;
for ($i=0; $i<=10; $i++)
{
echo $array[$i]."<br />";
}
echo "The average of these numbers is: ".$avg;
?>
Run Code Online (Sandbox Code Playgroud)