How Do I Do This?

  • Thread starter Thread starter Wayfarer
  • Start date Start date
W

Wayfarer

Can anyone please tell me how I can get this to work? Yes, it's
homework, but I just don't know how to take it any farther. It
won't show the total.

TIA

Neill

--

var L = prompt("Enter the length of carpet");
var W = prompt("Enter the width of carpet");
var C = prompt("Enter the cost per unit");

function carpet_cost(L,W,C)
{
var area = L * W;
var carpet_cost=(area * C);
}
return carpet_cost

window.alert ("The total cost of the carpet is", carpet_cost);
 
Thus spake Wayfarer:
Can anyone please tell me how I can get this to work? Yes, it's
homework, but I just don't know how to take it any farther. It
won't show the total.

TIA

Neill

--

var L = prompt("Enter the length of carpet");
var W = prompt("Enter the width of carpet");
var C = prompt("Enter the cost per unit");

function carpet_cost(L,W,C)
{
var area = L * W;
var carpet_cost=(area * C);
}
return carpet_cost

window.alert ("The total cost of the carpet is", carpet_cost);
Sorry, wrong newsgroup.
 
Can anyone please tell me how I can get this to work? Yes, it's
homework, but I just don't know how to take it any farther. It
won't show the total.

var L = prompt("Enter the length of carpet");
var W = prompt("Enter the width of carpet");
var C = prompt("Enter the cost per unit");

--------------------------------
function carpet_cost(L,W,C)
{
var area = L * W;
var carpet_cost=(area * C);
}
return carpet_cost
--------------------------------
window.alert ("The total cost of the carpet is", carpet_cost);

I'm not sure what language or script the above is, but each language
that I have used has the return value within the function:

--------------------------------
function carpet_cost(L,W,C)
{
var area = L * W;
var carpet_cost=(area * C);
return carpet_cost
}
--------------------------------

window.alert ("The total cost of the carpet is", carpet_cost);

You'll also need a variable in main to accept the returned value to,
such that the output statement can use it. Or, (not a great way of
programming):

--------------------------------
function carpet_cost(L,W,C)
{
var area = L * W;
var carpet_cost=(area * C);
window.alert ("The total cost of the carpet is", carpet_cost);
}
--------------------------------




Sorry if this does not apply to whatever you are using...
 
Can anyone please tell me how I can get this to work? Yes, it's
homework, but I just don't know how to take it any farther. It
won't show the total.

TIA

Neill

--

var L = prompt("Enter the length of carpet");
var W = prompt("Enter the width of carpet");
var C = prompt("Enter the cost per unit");

function carpet_cost(L,W,C)
{
var area = L * W;
var carpet_cost=(area * C);
}
return carpet_cost

window.alert ("The total cost of the carpet is", carpet_cost);

I don't know which language you are using but put your window alert
before your return statement. I would suggest that the window does not
know about carpet_cost as a variable.
 
Back
Top