I have a problem in JS that really burns in my soul!! I want to create a program that prompt the user to inter his name then his hourly wage then how many hours he has worked for? like: Enter your name please: Saleh Enter your hourly wage: 20 Enter the worked hours: 8
I need this program to print a message that says: Hello Saleh Your hourly wage is: 20 $ You have worked for: 8 hours Your payment is: 160 $
the program that i have made is working but the last line isn't giving any calculation! it prints NaN !!
Please help me
here's the code:
function Worker(aName, anHourlyWage, numberOfHours) // initializing the worker function that asked in the question.
{
this.name = aName;
this.anHourlyWage = anHourlyWage;
this.numberOfHours = numberOfHours;
this.setHourlyWage = setHourlyWage;
this.getName = getName;
this.getHourlyWage = getHourlyWage;
this.getHours = getHours;
this.calculatePayment = calculatePayment;
this.printDetails = printDetails;
}
function setHourlyWage(setHourlyWage) {
this.anHourlyWage = anHourlyWage2;
}
function getName() {
return this.name;
}
function getHourlyWage() {
return this.anHourlyWage;
}
function getHours() {
return this.numberOfHours;
}
function calculatePayment() {
return this.getHourlyWage * this.getHours; //to return the multiplication of working hours function and hourly wage function
}
function printDetails() {
window.alert("Hello: " + this.getName() +
"\n Your Wage Is: " + this.getHourlyWage() +
" $" + "\n You Have Worked For: " + this.getHours() + " Hours" +
"\n Your Payment Is: " + this.calculatePayment() + " $");
}
var name1 = window.prompt("Enter your name:", "");
var anHourlyWage1 = parseFloat(window.prompt("Enter the Hourly Wage:"));
var numberOfHours1 = parseFloat(window.prompt("Enetr the working hours:"));
var Worker1 = new Worker(name1, anHourlyWage1, numberOfHours1);
Worker1.printDetails();
thisis insetHourlyWage,getNameetc?Worker1.printDetails()call?