This is a small external js script for my web programming class, which should encourage the user to work from hours for employees until they enter a negative number when he prints a table with the corresponding number of rows (the number of employees for which the hours were entered) with a column for hours worked and salary column. But something in the for loop at the end is freezing the js engine in my browser. If I comment on the loop, the tips work fine. If I add an extra loop that prints something on the screen, the prompts still work, and then the while loop starts. But something in this stupid loop just freezes the whole script, and opening an HTML page literally does nothing. Empty page. The appointment is already delayed, and I am on my way.
var empHours = 0;
var numEmployees = 0;
var empWage = 0;
var totalWages = 0;
var empWages = new Array();
do {
empHours = prompt("Enter number of hours employee worked this week.");
if (empHours > -1) {
numEmployees++;
if (empHours <= 40) {
empWage = (15 * empHours)
empWages[numEmployees-1] = empWage;
totalWages += empWage;
} else {
empWage = (15 * 1.5 * empHours);
empWages[numEmployees-1] = (15 * 1.5 * empHours);
totalWages += empWage;
}
}
} while (empHours > -1);
confirm("You have " + numEmployees + " employees, is this correct?");
var root = document.getElementById('tablediv');
var table = document.createElement('table');
var row, cell;
for (i=0; i<=numEmployees; i++) {
document.write("Made it to for loop"):
row = table.insertRow(i);
for (j=0; j<3; j++) {
cell = row.insertCell(j);
cell.innerHTML(empWages[i])
}
}
root.appendChild(table);