Click here to Skip to main content
15,510,771 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I need an output for a function. This function has to return weekly pay. I think I have the function part the way I need it put I can't figure out to do an alert stating what the pay is. I need to be able for it to calculate regular pay or overtime pay depending on the hours and rate from the prompts. I can get the prompts to work but every alert statement I tried either did not give the weekly pay or if it did calculate the pay I could not get it to calculate for overtime pay.
Here is what I have so far:

C#
<html>
<head>
<script type="text/javascript">
function payForWeek(pay)
   {
   var regPay ;
   var overTime ;
   if (hours <=  40)
      regPay =  (hours * rate) ;
   else (hours > 40)
      overTime((hours - 40)*1.5*rate + 40*rate);
   return regPay ;
   return overTime ;
   }
var regPay;
var overTime;
hours  = prompt ("Enter your hours",  "") ;
rate  = prompt ("Enter your rate",  "") ;


</script>
</head>
</html>
Posted
Updated 29-Sep-10 5:56am
v3
Comments
Sushant Joshi 29-Sep-10 23:06pm    
Hi, Did you try the method suggested by me, did it work ?

I have indented your original question, and revealed the answer.
Originally, I indented it because it makes it easier to read, but it shows clearly what your problem is: If your code executes a return statement, it leaves the function. So any statements after the first return will never be executed.
 
Share this answer
 
Write three JS Functions, and add them on page load like

<body onload="javascript:fnSaveHours();fnSaveRate();fnCalculatePay();"> 
</body>


In the first two functions, save the value in respective hidden variables in the page by capturing through prompt. In the last calculate the Pay based on two previously captured values.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900