Computer Forums

Member Login

Remember Me? Sign Up! | Forgot Password
 
Slogan
 
Closed Thread
Old 06-10-2009, 05:25 PM   #1 (permalink)
 
Newb Techie

Join Date: Jun 2009

Posts: 1

JCurtnerStudent is on a distinguished road

Default Beginner Javascript help

Hello All,

This is my first time using javascript.. I am trying to do my first homework assignment which is basically to make a page that will calculate gross pay. when i try and run it in a browser the dialog boxes pop up and ask the user for the information but thats where it stops. Can anyone give me a little help or at least lead me in the right direction as to where im making my mistakes? I would really appreciate it!! Thanks much! Jessica



Code:
<?xml version = "1.0" encoding = "utf-8"?>
<!DOCTYPE html PBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3/org/TR/xhtml1/DTD/xhtml1-strict.dtd">

<html xmlns = "http://www.w3.org/1999/xhtml">

   <head>
     <title>Calculating gross pay</title>
	 <script type = "text/javascript">
	  
	  //define variables
	  
	   var name; //user name
	   var hourlyWage; //users hourly rate
	   var hoursWorked; //hours user worked
	   var netPay; //pay before taxes taken out
	   var grossPay; //pay after taxes taken out
	   var fedTaxes; //amount of federal taxes held
	   var stateTaxes; //amount of state taxes held
	   var fica; //amount of fica taxes held
	   var overtimeHours;
	   var regHours;
	 
	   
	   //Get users name
	   name = window.prompt( "Please enter your name" );
	   
	   //Get users hourly wage
	   hourlyWage = window.prompt( "Please enter your hourly wage" );
	   
	   //get users hours worked
	   hoursWorked = window.prompt( "Please enter amount of hours worked" );
	   
	   
	   if(hoursWorked > 40)
	   { 
	     overtimeHours = hoursWorked - 40;
		 regHours = 40;
	   }
	   
	   if(HoursWorked < 40)
	   {
		  OvertimeHours = 0;
		  regHours = HoursWorked;
	   }
		  //calculate gross pay	  
		  grossPay = regHours * HourlyWage + 1.5*(overtimeHours * HourlyWage);
		  
		  //calculate taxes
		  fedTaxes = grossPay / .20;
		  stateTaxes = grossPay / .3;
		  fica = grossPay / .8;
		  
		  //calculate net pay
		  
		 netPay = grossPay - fedTaxes - stateTaxes - fica;
		 
		 
		 document.writeln(<h1> " BHC Group " + name "pay" </h1> );
		 
		 document.writeln ("name" + name );
		 document.writeln ("gross pay = " + grossPay );
		 document.writeln ("federal taxes withdrew = " + fedTaxes );
		 document.writeln ("State taxes withdrew = " + stateTaxes );
		 document.writeln ("FICA withdrew = " + fica );
		 document.writeln ("Net pay = " + netPay );
		 
		 </script>
		</head>
	    <body>
		</body>
</html>

JCurtnerStudent is offline  
Old 06-10-2009, 05:49 PM   #2 (permalink)
 

Join Date: Jul 2005

Location: England

Posts: 2,157

kmote has a spectacular aura aboutkmote has a spectacular aura about

Default Re: Beginner Javascript help

Sorry, but we can't help with homework. One thing I will say is that most browsers have an option to open a console or other descriptive error dialogue on javascript errors using that will give you fair insight into whats going wrong.

EDIT: that might be a little harsh... you should check the casing on your variables. If necessary you could use an alert to show where your code is getting up to.
__________________
MSI P43 Neo|Enermax Pro82+ 425W|E5200|silent 8500GT|250GB Samsung spinpoint F1|Samsung SATA DVD RW|4GB Corsair|Antec SOLO|openSUSE11


There are in order of increasing severity: lies, darn lies, statistics, and computer benchmarks. - diskinfo man page

Last edited by kmote; 06-10-2009 at 05:57 PM.
kmote is offline  
Old 06-10-2009, 08:17 PM   #3 (permalink)
oldskool's Avatar
 
Electrical Systems Design

Join Date: Jun 2008

Location: Maine, USA

Posts: 1,646

oldskool has a spectacular aura aboutoldskool has a spectacular aura about

Default Re: Beginner Javascript help

Be patient JCurtnerStudent, Kmote is one of the best coders around here, along with a few others. If you stay around - and we hope you do - you will know who they are. As Kmote said, you have to do your own homework, however if you remain patient, we can give ideas for you to try, and in doing so, you will learn much quicker and more efficiently than if someone just plasters the code here. That said ...

...Some good things to think about when you are starting out in any language, is to start "small". What I mean by that is, after you have all your basic script down, you can add things a little at a time, and by using Kmote's suggestion, add an alert box in key places, such as in a function that you add to your basic script.

That technique has helped me a lot. What it does, is when the code executes properly up until the point of the inserted alert box text, you will know that your code is fine up to that point. Then move the alert box text to the next part, and so forth. When you don't see an alert box pop up, then you will know something was wrong.

I know this all above what you asked for, and may be a bit too advanced of an answer for you to comprehend since you are a beginner, but stay with it, and we will see if we can help.
oldskool is offline  
Old 06-10-2009, 08:44 PM   #4 (permalink)
CrazeD's Avatar
 
Wizard Techie

Join Date: Feb 2006

Location: Maine

Posts: 3,683

CrazeD will become famous soon enough

Send a message via AIM to CrazeD Send a message via MSN to CrazeD
Default Re: Beginner Javascript help

Since I'm a nice guy, I will help you.

The reason you don't get any output is because the script encounters an error and it terminates the script. Javascript errors, by them self, are very ambiguous and sometimes hard to detect. Therefore, you really need to get some debug tools. I HIGHLY recommend the Firebug plugin for Firefox. It is an excellent tool for Javascript/AJAX developers. You can step through the code line-by-line, setup breakpoints, find errors, make on-the-fly changes...etc.

Your error is that you have mixed the case of your hoursWorked variable, as well as some others. Those aren't the only errors, but I'll let you try to figure the rest out.
__________________

Need website help? PM me!
CrazeD is offline  
Old 06-11-2009, 08:20 AM   #5 (permalink)
 

Join Date: Jul 2005

Location: England

Posts: 2,157

kmote has a spectacular aura aboutkmote has a spectacular aura about

Default Re: Beginner Javascript help

Well that should be enough to get the OP on the right track. Tread closed.
__________________
MSI P43 Neo|Enermax Pro82+ 425W|E5200|silent 8500GT|250GB Samsung spinpoint F1|Samsung SATA DVD RW|4GB Corsair|Antec SOLO|openSUSE11


There are in order of increasing severity: lies, darn lies, statistics, and computer benchmarks. - diskinfo man page
kmote is offline  
 
Closed Thread

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Using javascript to hide and unhide elements dynamically Osiris Programming Discussions 0 01-14-2009 08:56 PM
Firefox 3.1 beta arrives with JavaScript booster turned off Osiris Browser & General Internet Questions 3 10-15-2008 03:50 PM
The A-Z of Programming Languages: JavaScript Osiris Programming Discussions 0 08-04-2008 09:35 AM
PHP: How to modify a downloaded JavaScript code and partly change the code within it? LincolnX Programming Discussions 4 01-25-2008 04:25 PM