When you select the model of car and the metal, you need to return how many bars fit in the area.
It will then take the amount of total bars that can fit and then multiply that by .33. This in turn is multiplied by the weight of the metal (I set that as part of an array) and the result is subtracted from 1800. If that result is < 0, it will respond "You did not get away" else it respond "you got away!"
I know this code is far from done but I want to see if I am going the right direction.
<HTML>
<title>
Trying to get this program to work.
</title>
<script type="text/javascript">
<head>
var carType = new Array();
carType["2 door"]=41446;
carType["4 door"]=52776;
var metal= new Array();
metal["Al"]=4.3512;
metal["Au"]=30.9912;
metal["Pt"]=34.09692;
metal["Ag"]=16.8276;
function weightUsed()
{
var spaceUsed=0;
var theForm = document.forms["carform"];
var selectedCar = theForm.elements["selectedCar"];
for(var i = 0; i < selectedCar.length; i++)
{
if(selectedCar[i].checked)
{
spaceUsed = carType[selectedCar[i].value];
break;
}
}
return spaceUsed;
}
function getmetalWeight()
{
var carmetalspace=0;
var theForm = document.forms["carform"];
var selectedmetal = theForm.elements["metal"];
carmetalspace = metal[selectedmetal.value];
return carmetalspace;
}
{
var theForm = document.forms["carform"];
{
var theForm = document.forms["carform"];
}
function calculateTotal()
{
var metalWeight = weightUsed() + getmetalWeight();
var divobj = document.getElementById('totalWeight');
divobj.style.display='block';
divobj.innerHTML = "The weight of the metal in the space is "+metalWeight;
}
function hideTotal()
{
var divobj = document.getElementById('totalWeight');
divobj.style.display='none';
}
</script>
<body style="background-color:burlywood">
In <i>The Italian Job</i>, theives were able to steal bars of gold by loading them into Mini Coopers and driving away.<p>
<p>
It is now your turn to pull your own version of <i>The Italian Job</i>. You are able to choose what model of Mini you use and the type of metal bar you want to steal.<p>
Thes rules are:<ul>
<li>You can only load the cargo area of your Mini 1/3 of the way full</li>
<li>The cargo area used cannot weigh more than 1800 lbs.</li>
</ul>
<p>
The models of Mini available are either a 2 or a 4 door. The 2 Door has 25 cubic feet of cargo space - the 4 door 35.4.
<p>
The metal bars are Aluminum, Gold, Platinum and Silver.
<p>
<div>
<form>
Which car do you want to use? <br />
<Input type = "radio" Name = car Value = "2door">2 door <br />
<Input type = "radio" Name = car Value = "4door">4 door <br />
<br />
<p> Now choose the metal you want to try to steal. <br />
<Input type = "radio" Name = metal Value = "Al">Aluminum <br />
<Input type = "radio" Name = metal Value = "Au">Gold <br />
<input type = "radio" Name = metal Value = "Pt">Platinum <br />
<input type = "radio" Name = metal Value = "Ag">Silver <br />
</form>
</div>
</body>
</HTML>

New Topic/Question
Reply


MultiQuote






|