Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8563333
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T16:56:12+00:00 2026-06-11T16:56:12+00:00

This is a little external js script for my web programming class, which is

  • 0

This is a little external js script for my web programming class, which is supposed to prompt the user for hours worked for employees, until they enter a negative number, when it prints a table with the appropriate number of rows (the number of employees for which hours were entered for) with a column for hours worked and a column for wage. But something about the for loop at the end is freezing the js engine in my browser. If I comment the loop out, the prompts work fine. If I put in a nonsense while loop which prints something to the screen, the prompts still work and then the while loop runs. But something about this stupid for loop just freezes the whole script, and opening the HTML page literally does nothing. Blank page. The assignment is already late and I’m at my wits end.

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);
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T16:56:14+00:00Added an answer on June 11, 2026 at 4:56 pm

    Prompt returns null or a string. It does not return a number.

    I would suggest you change to:

    while (empHours && parseInt(empHours, 10) >= 0)
    

    This guards against null and converts the string to a number before checking to see if it’s negative.

    Also, I would suggest you NOT use document.write() for debugging, ever. It can really mess up an existing page if used at the wrong time. You should be using console.log() or an actual debugger.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

have written this little class, which generates a UUID every time an object of
I have this little problem, that I cannot figure out which arguments to pass
I'm new to javascript and cant get this little thing to work. (all external
I've created a little class to generate thumbnails with an external program ( gm
This little bit of syntax has been a bit of a confusion for me
found this little code snippet that seems to do what i want, but im
Given this little piece. http://jsfiddle.net/4gb6K/7/ I am attempting to align the bot element at
Given this little fiddle: http://jsfiddle.net/5Sw3h/8/ I have a navigation panel to the left, a
I have taken this little snippet straight out of some code I'm working on:
So I got this little piece of code, don't bother the way it's implemented.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.