View Single Post
Old 12-04-2012, 07:00 AM   PM User | #2
devnull69
Senior Coder

 
Join Date: Dec 2010
Posts: 2,261
Thanks: 10
Thanked 533 Times in 527 Posts
devnull69 will become famous soon enough
This is your code in a readable format
Code:
function getVolume(l, w, h) {
   var v;

   v= l * w * h;
   return v;
}

var length, width, height;

length = parseFloat(prompt("Enter length"));
width = parseFloat(prompt("Enter width"));
height = parseFloat(prompt("Enter height"));
getVolume(length, width, height);

function getWeight() {
   var w;

   w = weight;
   return w;
}

var weight;

weight = parseFloat(prompt("Enter weight"));
if (v <= 1000000 && w <= 1000 ) {
   alert("Thank you for shipping with us!");
} else if (v >1000000 ) {
   alert("Your chocolates will not fit the container.");
} else (w > 1000) {
   alert("Your chocolates are to heavy for the container.");
}
It seems like you have problems understanding the concepts of "global and local variables" and "functions with return values".

1 - You are accessing the variable w in the global scope (i.e. outside of any function). But you declared w to be local to the function "getWeight". Outside of this function you neither declare nor define it, so it is undefined.
2 - You define a function getWeight, but you never call it
3 - You define and call the function getVolume, but you don't assign the return value to any variable in your global scope. So the result (return value) is lost

Can you work with this or do you need additional assistance?
devnull69 is offline   Reply With Quote