I need help with a javascript script that will print the gross pay for 3 workers. The script will ask the three workers their: name, pay rate, hours worked. If they worked overtime (40+ hours) they will get 1.5 times the pay rate for the ovetime hours. The script will print the name and the gross pay for each of the 3 workers. This is what I have: <script> <!-- var grosspay, grosspayValue, overtime, overtimeValue, overtimepay, hours, pay; hours = window.prompt( "Enter hours worked:"); grosspay = window.prompt( "Enter your grosspay:" ); grosspayValue = parseInt( grosspay ); overtimeValue = parseInt( overtime ); if ( hours >= 40 ) { pay = hours * grosspayValue; } document.writeln( "Total Pay is: " + pay ); else if ( hours > 40 ) { overtimepay = hours - 40 * pay * 1.5; } document.writeln( "Total Pay is: " + overtimepay ); //--> </script>
<script language="javascript"> window.onload=function() { var name, rate, hours ; name = window.prompt('What is your name ?'); rate = window.prompt('What is your rate of pay ?'); hours = window.prompt('How many hours have you worked ?'); document.write( name + ' wages<br />' ); if( hours > 40 ) { overtime = hours - 40 ; hours = 40; } document.write( 'Net Pay : $' + ( hours * rate ) + '<br />' ); if( overtime ){ document.write( 'Overtime : $' + overtime * ( rate * 1.5 ) + '<br/>'); } } </script> HTML: OR <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Untitled Document</title> <script language="javascript"> function element( element ) { return document.getElementById(element) ; } function makeWages( hours ) { if( hours > 40 ) { overtime = hours - 40 ; hours = 40 ; } element('overtime').innerHTML = overtime ; wages = hours * element('rater').innerHTML ; wages += element('overtime').innerHTML * ( element('rater').innerHTML * 1.5 ); element( 'wagesr' ).innerHTML = '$'+wages; } </script> </head> <body> <form action="" method="post"> Please enter your name : <input type="text" id="name" name="name" onkeyup="element('namer').innerHTML = this.value ;"/><br /> Please enter your rate of pay : <input type="text" name="rate" id="rate" onkeyup="element('rater').innerHTML = this.value ;"/><br/> How many hours have you worked ? : <input type="text" name="hours" id="hours" onkeyup="makeWages( this.value );"/><br /> </form> <div id="wages"> Name : <span id="namer"></span><br /> Rate : <span id="rater"></span><br /> Overtime : <span id="overtime"></span><br /> Wages : <span id="wagesr"></span><br /> </div> </body> </html> HTML: