I have a javascript function that is returning a value. However, I can not get the value to return outside of the function. I have researched and can not figure out the issue. It says grossResults in the last line of code is undefined. Wouldn't the return make it accessible?
"use script";
var hourlyRate = prompt("Enter hourly pay rate:", hourlyRate);
var totalHrsWorked = parseInt(prompt("Enter number of hours worked:", totalHrsWorked));
//function to calculate gross wages for an hourly employee
function grossWages (hourlyRate, totalHrsWorked){
var OTHours = totalHrsWorked - 40;
var regPay = (totalHrsWorked - OTHours) * hourlyRate;
var OTPay = (OTHours * (hourlyRate * 1.5)) + regPay;
grossResults = (OTHours > 0) ? OTPay : regPay;
return grossResults;
};
document.writeln("<br /><br />");
document.writeln("Pay rate entered: " + hourlyRate + "<br />");
document.writeln("Hours entered: " + totalHrsWorked + "<br />");
document.writeln("Gross Pay: $" + grossResults + "<br /><br />")
") ` – LcSalazar Oct 02 '14 at 20:26