I have if Else statements that always returns the else part of the statement but never the "if" side. Could you look at my code and tell me where I am going wrong? I am aware I have too many variables declared.
Code:var car_type = new Array(); car_type["2door"]=41446; car_type["4door"]=52776; //Set up array that represents the metal_type weight var metal_type= new Array(); metal_type["selectmetal"]=0; metal_type["Aluminum"]=4.3512; metal_type["Gold"]=30.9912; metal_type["Platinum"]=34.09692; metal_type["Silver"]=16.8276; // getCarStorage() finds the storage based on the car storage space. function getCarStorage() { var carStorageArea=0; //refers form id="carForm" var theForm = document.forms["carForm"]; var selectedCar = theForm.elements["selectedCar"]; carStorageArea = document.getElementById("selectedCar").value; //We return carStorageArea return carStorageArea; } //This function finds the metal bar weight function getMetalDensity() { var carStorageSpace=0; //Get a reference to the form id="carForm" var theForm = document.forms["carForm"]; //Get a reference to the select id="metal" var selectedmetal = theForm.elements["metal"]; //equal to value user chose such as metal_type["Aluminum".value] would be equal to 4.3512 carStorageSpace = metal_type[selectedmetal.value]; //finally we return carStorageSpace return carStorageSpace; } function calculateTotal() { var divobj = document.getElementById('total'); //Here we get the total by calling our function //Each function returns a number var totalCanFit = getCarStorage() / 440; var spaceUsable = totalCanFit * .33; // var fit = car_type / 44.40625; var metal_name = document.getElementById("metal").value; var barsNeededFor1800 = 1800 / metal_type[metal_name]; var total = barsNeededFor1800 * metal_type[metal_name]; var barLimit = totalCanFit / spaceUsable; var weightLimit = barsNeededFor1800 / spaceUsable; var doesFit = barsNeededFor1800 - totalCanFit var respond = "You will not be able to complete this job. Please select either another car or bar type."; if (barLimit <1) { divobj.innerHTML = ("This will not work because you have surpassed the limit of " + barLimit.toFixed(0) ); } else if (weightLimit <1) { divobj.innerHTML = ("This will not work: wl="+ weightLimit+","+spaceUsable+","+barsNeededFor1800+";"); } else { respond = 'With the total cargo area of the chosen car, you are able to fit ' +totalCanFit.toFixed(0) + ' bars. You will need ' + barsNeededFor1800.toFixed(0) + ' bars to reach to the 1800 lbs limit. ';


Reply With Quote
and a skill you need to develop if you're going to be a coder of any kind.



Bookmarks