我的代码应该通过将油箱容积除以行驶距离来计算车辆的油耗,然后在表格行“油耗”中显示答案。然后,“最高效”的列应该在最高效的车辆。
作业说要使用一个对象,但我只是不明白它们是如何工作的。请帮忙,我被卡住了。
<table>
<tr>
<th>Registration Number</th>
<th>Volume of fuel tank (litres)</th>
<th>Distance traveled on full tank (km) </th>
<th>Fuel consumption (litres/Km) </th>
<th>Most efficient</th>
</tr>
<tr>
<td><p id="registration1"></p></td>
<td><p id="tank1"></p></td>
<td><p id="distance1"></p></td>
<td><p id="consumption1"></p></td>
<td><p id="efficient1"></p></td>
</tr>
<tr>
<td><p id="registration2"></p></td>
<td><p id="tank2"></p></td>
<td><p id="distance2"></p></td>
<td><p id="consumption2"></p></td>
<td><p id="efficient2"></p></td>
</tr>
<tr>
<td><p id="registration3"></p></td>
<td><p id="tank3"></p></td>
<td><p id="distance3"></p></td>
<td><p id="consumption3"></p></td>
<td><p id="efficient3"></p></td>
</tr>
<tr>
<td><p id="registration4"></p></td>
<td><p id="tank4"></p></td>
<td><p id="distance4"></p></td>
<td><p id="consumption4"></p></td>
<td><p id="efficient4"></p></td>
</tr>
</table>
<script>
var i = 1;
var registration = [];
var tank = [];
var distance = [];
var consumption = [];
function Vehicle() {
for (i = 1; i < 5; i++) {
registration.push(prompt("Please enter a 6-character vehicle registration number"));
document.getElementById("registration" + i).innerHTML = registration[i - 1];
tank.push(prompt("Please enter the volume of the vehicle's fuel tank in litres"));
document.getElementById("tank" + i).innerHTML = tank[i - 1];
distance.push(prompt("Please enter the distance the vehicle can travel on a full tank of fuel"));
document.getElementById("distance" + i).innerHTML = distance[i - 1];
明月笑刀无情
紫衣仙女
相关分类