Assignment 3 -Intro to programming javascript
MIT 153 – Assignment #3
Create a program that will be used to calculate the payroll
for a small company.
They will have a variable number of employees, and we need
to do the same calculations for each employee.
For each employee the program will ask for their name and the
number of they hours worked. It will then calculate how much they earned at a
wage of $10.00 per hour. It will then display the employee’s name and the
amount they earned in the document window. (Note: Depending on the browser you
use, this output may not appear until the JavaScript has terminated.)
It will continue processing employees until they enter “END”
as the employee name.
At that point it will display the total hours worked and the
total earnings.
Design the algorithm for your program using pseudo-code or a flow chart. Then implement it in JavaScript. Put you files in a zip and upload them using this link.
pseudo-code
//Assignment#3
START
//DECLARATION
DECLARE string name
DECLARE numeric hours
DECLARE wage As number=10
DECLARE numeric totalEarn
DECLARE string END
DECLARE hoursCount As number=0
DECLARE totalCount As number=0
START
DISPLAY “Enter Employee Name”
INPUT name
while name!==END
DISPLAY"Enter Number of Hours Worked"
INPUT hours
totalEarn=wage*hours
hoursCount=hours+hoursCount
totalCount=totalEarn+totalCount
DISPLAY name
DISPLAY totalEarn
DISPLAY "Enter Employee Name"
INPUT name
DISPLAY name
DISPLAY totalEarning
End While
DISPLAY hoursCount
DISPLAY totalCount
STOP
Java Code
<html>
<body>
<script type="text/javascript">
// MIT 153-Assiggnment#3
// DECLARATION
var name;
var hours;
var wage=10;
var totalEarn;
var END
var hoursCount=0;
var totalCount=0;
var BR="<br/>";
// INPUT
name =prompt("Enter Employee Name:","");
//THE WHILE LOOP
while (name!=="END") {
hours =prompt("Enter Number of Hours Worked:","");
totalEarn=wage*hours;
hoursCount=parseFloat(hours)+parseFloat(hoursCount);
totalCount=parseFloat(totalEarn)+parseFloat(totalCount);
document.write("Employee Name: " + name + BR);
document.write("Total Earning: " + totalEarn + BR+ BR);
name =prompt("Enter Employee Name:","");
}
document.write("Total Hours Worked: " + hoursCount + BR);
document.write("Total Earnings: $" + totalCount + BR);
</script>
</body>
</html>
Leave a reply