Good evening everyone. I am new here and also new to JavaScript. I have a small assignment that I think I have just about done, but the False part of my conditional expression is not calculating properly. My program keeps 'spitting out' the same calculation of rate times hours if the hours worked are below 40 and if the hours worked are above 40 instead of doing different calculation for both. My conditional expression (?) is calculating the true part correct, but not the false part. Below is my .js file that I have.
/**
* @author Administrator
*/
//If hours worked are less than 40,
//your regular pay rate will be used.
//Otherwise employee will be paid one and a half times their regular pay rate,
//for hours worked over 40.
function calculateGross(hours, rate)
{
var pay = rate * hours;
pay = parseFloat (pay, 2);
var overTime = ((hours - 40) * (1.5 * rate)) + (rate * 40);
overTime = parseFloat (overTime, 2)
var result;
result = parseFloat(result, 2);
hours <= 40 ? result = pay : result = overTime;
document.writeln(result);
}
Here is my .html file with the appropriate prompts:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Gross Pay Amount</title>
<script type="text/javascript"
language="Javascript"
src ="grossPayAmount.js">
</script>
</head>
<body>
<script type="text/javascript" language="JavaScript">
var hoursWorked = prompt("Enter the number of hours worked:", "Enter hours worked here.");
</script>
<script type="text/javascript" language="JavaScript">
var hourlyRate = prompt("Enter hourly pay:", "Enter hourly pay here.");
calculateGross (hourlyRate, hoursWorked);
</script>
</body>
</html>
Does anybody see my error? Is it in my overTime formula or do I have something else wrong? Any help would be sincerely appreciated. Thanks in advance and have a great weekend everyone.