Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

simplest javascript function won't work

Status
Not open for further replies.

photoxprt1868

Programmer
Jul 22, 2005
76
0
0
US
Hello,

I'm writing what I think is a simple formula, but it's working at all. Can someone tell me if there's anything wrong with my syntax

Code:
<head>
<SCRIPT LANGUAGE="JavaScript">

function calculateCost(kwh){
var custCharge2005 = 5.25;
var custCharge2006 = 0;
var first750KWH = 0.04302;
var first750 = 0;
var over750KWH = 0.05232;
var over750 = 0;
var fuelCharge = 0.04009;
var cost2005 = 0;
var cost2006 = 0;

if (kwh > 750){
	first750 = 750;
	}
	else{
		first750 = kwh;
	}

if (first750 < kwh){
	over750 = kwh - first750;
	}
	else{
		over750 = 0;
	}

cost2005 = custCharge2005 + (first750kwh * first750) + (over750kwh * over750) + (fuelCharge * kwh) - 1.36;


alert(cost2005);
}
</script>
</head>

<body onLoad="calculateCost(1000);">



</body>
 
Javascript is case-sensitive.

first750KWH is not the same as first750kwh

Cheers,
Dian
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top