Is it possible to nest functions within a main function in JavaScript? I've been playing around with some code, and I can't get my function to display anything to the screen.
function main() {
var crew;
var crewMemberWeight = 113;
var winterWeight = 2.8;
var winter = false;
var capacity = 24000;
var cargo = [1000, 5500, 2000, 3500, 4000, 7000];
function cargoWeight(cargo) {
total = 0;
for(var i = 0; i < cargo.length; i++) {
total += cargo[i];
}
document.write("Cargo weight: " + total);
return total;
}
}
main();
cargoWeightanywhere.cargoWeight(load)outside themain()and call it like you would any other function. IEcargoWeight(2000);