The new forums will be named Coin Return (based on the most recent vote)! You can check on the status and timeline of the transition to the new forums here.
The Guiding Principles and New Rules document is now in effect.

Simple javascript stupidity

Judge Joe BrownJudge Joe Brown Registered User regular
edited April 2009 in Help / Advice Forum
So it's that time in my life where I'm stuck in another computer science course and remembering very little of the things I used to know. Very very basic stuff, we do a chapter in Word, Excel, all that good stuff, total breeze, but I'm on this java assignment and getting stuck in places I shouldnt be! I decided I was going to skip the labs and not brush up on java, but that was a stupid mistake because now I can't remember some syntax and in general Im fucking this up.

So here's the code, basically you can skip down to the bottom where the form is created. I don't think the form is reading in my variables in such a way that the calculate function is actually getting them. It's like 5 in the morning here and I have to submit this in the AM so any resources or pointers would be appreciated, I'm overlooking some little things here for sure. Forgive the formatting, I know I'm not supposed to be starting variables with capitals etc but we're not getting marked on formatting so I got lazy. I tried to clean up the most ridiculous areas.

Simple assignment, reads in your income, purchased RRSPS and how much you've paid the taxman already, supposed to return your tax rate based on arbitrary numbers given to us in the assignment and then draw a graph of asterixes on the bottom based on each 10% of the tax rate. 70% = 7 asterixes etc. Also needs to output your tax owed or refund due.
<html>
<head>
</head>
<body>

  <script language= "JavaScript">

   function calculate()
    {
      var Income, Rrsp, Taxespaid, Taxrate, Refund, stars;
      Income = parseInt (document.taxman.income.value);
      Rrsp = parseInt (document.taxman.rrsp.value);
      Taxespaid = parseInt (document.taxman.taxespaid.value);
      Taxrate = parseInt (document.taxman.taxrate.value);
      Refund = parseInt (document.taxman.refund.value);
      stars = parseInt(document.taxman.taxrate.value) /10;
    
if (document.taxman.Select1.options[document.taxman.Select1.selectedIndex].value=="Normal")
      {
      if(Income >= 70000)
	 {
           Taxrate=70;
	   document.taxman.taxrate.value= Taxrate;
	 }
      else if(Income <= 20000)
	 {
           Taxrate=10;
	   document.taxman.taxrate.value= Taxrate;
	 }
      else
	 {
           Taxrate=25;
	   document.taxman.taxrate.value= Taxrate;
	 }

 
      if (document.taxman.stuff[0].checked==true)
	 {
	   Taxrate = (Taxrate - 20);
	   document.taxman.taxrate.value = Taxrate;
	 }

      else if(document.taxman.stuff[1].checked==true)
	 {
	   Taxrate = (Taxrate - 30);
	   document.taxman.taxrate.value = Taxrate;
	   
	  
      else if(document.taxman.stuff[2].checked==true)
	 {
	   Taxrate = (Taxrate - 50);
	   document.taxman.taxrate.value = Taxrate;	
	 }
      else
	 {
	 }
      
      	 
      if(document.taxman.over65[0].checked==true)
	 {
	   Taxrate = (Taxrate/2);
	   document.taxman.taxrate.value = Taxrate;
	 }
      else
	 {
	 }
     
      if (Taxrate >= 70)
         {
           window.alert("Oh YA, Gimme your money!");
         }
      else if (Taxrate <= 20)
         {
           window.alert("I am going to audit you!");
      else
         {
	 }
	 }  
         }
if (document.taxman.Select1.options[document.taxman.Select1.selectedIndex].value=="Lawyer")
         {
	   Taxrate = 100;
           window.alert("I love taking money from Lawyers!");
	   document.taxman.showit.value=document.taxman.Select1.options[3].value;
         }
if (document.taxman.Select1.options[document.taxman.Select1.selectedIndex].value=="Hardship Claimed")
	 {
	    Taxrate = Taxrate - 20);
	    document.taxman.taxrate.value = Taxrate;
	 }
if (document.taxman.Select1.options[document.taxman.Select1.selectedIndex].value=="Mercy")
	 {
	    Taxrate = Taxrate - 10);
	    document.taxman.taxrate.value = Taxrate;
	 }

	
	for (var count = 1; count <= stars; count = count + 1)
       {
        document.taxman.display.value = document.taxman.display.value + "*";
       }
     
      Taxrate = (Taxrate/100)
      Refund = (Income * Taxrate) - Taxespaid;
      document.taxman.refund.value= Refund;
    
   } 
 
 function cleargraph()
   {
    document.taxman.display.value = " ";
   } 


</script>
<br>
<center>
<H1><b><u>The Taxman</u></b></H1>
</center>
<br>
<b> Your Tax Information </b>
<br>
<form name="taxman">
<table border = "3">
	<tr><td>Income</td><td><input name=“income” type=“number”  size=“12”></td></tr>
	<tr><td>RRSP</td><td> <input name=“rrsp” type=“number” value="0" size=“12”></td></tr>
	<tr><td>Tax Rate</td><td> <input name=“taxrate” type=“number” size=“12”></td></tr>
	<tr><td>Taxes Paid</td><td> <input name=“taxespaid” type=“number” value="0" size=“12”></td></tr>
	<tr><td>Refund or Due</td><td> <input name=“refund” type=“number” value="0" size=“12”></td></tr>
	</table>
	<br>
	<br>
	<b>Extra Deductions
	Children <input name="stuff" checked type="radio">
	Spouse <input name="stuff" checked type="radio">
	Both <input name="stuff" checked type="radio">
	None <input name="stuff" checked type="radio">
	<br>
	<br>
	Over Age 65? <input name="over65" Checked type="checkbox">
	<br>
	<br>
	<input name="Taxrate" type="button" value="Calculate your Tax" onclick="calculate(Taxrate)">
	<input type="button" value="Clear Display Area" onclick="reset()">
	<br>
	<br>
	<b> Special Cases </b>
	   <SELECT ID = Select1>
	    <OPTION value = "Normal" >Normal</OPTION>
	    <OPTION value = "Hardship Claimed" >Hardship Claimed</OPTION>	
	    <OPTION value = "Mercy" >Mercy</OPTION>
	    <OPTION value = "Lawyer" >Lawyer</OPTION>
	   </SELECT>

<br>
<br>
<b>Your Text Rate</b>

<br>
<textarea name="yourtaxrate" rows="10" cols="30">
</textarea>
</form>
</body>
</html>


Thanks in advance. Yes I know how bad I am at java.

Judge Joe Brown on

Posts

  • JoeUserJoeUser Forum Santa Registered User regular
    edited March 2009
    OK, a few things:

    1) Your parentheses aren't matching up, so you're getting syntax errors in the main calculate function
    2) Some of your assignment statements have an extra )
    3) For some reason, the quotes for the name on your form items are different from normal quotes. I'm not sure if this is a forum thing, but I had to correct them to get it to work.
    4) over65 is a checkbox, not an array

    The following corrected code will at least bring up the message boxes:
    <html>
    <head>
    </head>
    <body>

    <script language= "JavaScript">

    function calculate(form)
    {
    var Income, Rrsp, Taxespaid, Taxrate, Refund, stars;
    Income = parseInt (document.taxman.income.value);
    Rrsp = parseInt (document.taxman.rrsp.value);
    Taxespaid = parseInt (document.taxman.taxespaid.value);
    Taxrate = parseInt (document.taxman.taxrate.value);
    Refund = parseInt (document.taxman.refund.value);
    stars = parseInt(document.taxman.taxrate.value) /10;

    if (document.taxman.Select1.options[document.taxman.Select1.selectedIndex].value=="Normal")
    {
    if(Income >= 70000)
    {
    Taxrate=70;
    document.taxman.taxrate.value= Taxrate;
    }
    else
    if(Income <= 20000)
    {
    Taxrate=10;
    document.taxman.taxrate.value= Taxrate;
    }
    else
    {
    Taxrate=25;
    document.taxman.taxrate.value= Taxrate;
    }


    if (document.taxman.stuff[0].checked==true)
    {
    Taxrate = (Taxrate - 20);
    document.taxman.taxrate.value = Taxrate;
    }

    else
    if(document.taxman.stuff[1].checked==true)
    {
    Taxrate = (Taxrate - 30);
    document.taxman.taxrate.value = Taxrate;
    }

    else
    if(document.taxman.stuff[2].checked==true)
    {
    Taxrate = (Taxrate - 50);
    document.taxman.taxrate.value = Taxrate;
    }
    else
    {
    }


    if(document.taxman.over65.checked==true)
    {
    Taxrate = (Taxrate/2);
    document.taxman.taxrate.value = Taxrate;
    }


    if (Taxrate >= 70)
    {
    window.alert("Oh YA, Gimme your money!");
    }
    else
    if (Taxrate <= 20)
    window.alert("I am going to audit you!");

    }

    if (document.taxman.Select1.options[document.taxman.Select1.selectedIndex].value=="Lawyer")
    {
    Taxrate = 100;
    window.alert("I love taking money from Lawyers!");
    document.taxman.showit.value=document.taxman.Select1.options[3].value;
    }
    if (document.taxman.Select1.options[document.taxman.Select1.selectedIndex].value=="Hardship Claimed")
    {
    Taxrate = Taxrate - 20;
    document.taxman.taxrate.value = Taxrate;
    }
    if (document.taxman.Select1.options[document.taxman.Select1.selectedIndex].value=="Mercy")
    {
    Taxrate = Taxrate - 10;
    document.taxman.taxrate.value = Taxrate;
    }


    for (var count = 1; count <= stars; count = count + 1)
    {
    document.taxman.display.value = document.taxman.display.value + "*";
    }

    Taxrate = (Taxrate/100)
    Refund = (Income * Taxrate) - Taxespaid;
    document.taxman.refund.value= Refund;

    }

    function cleargraph()
    {
    document.taxman.display.value = " ";
    }


    </script>
    <br>
    <center>
    <H1><b><u>The Taxman</u></b></H1>
    </center>
    <br>
    <b> Your Tax Information </b>
    <br>
    <form name="taxman">
    <table border = "3">
    <tr><td>Income</td><td><input name="income" type="number" size="12"></td></tr>
    <tr><td>RRSP</td><td> <input name="rrsp" type="number" value="0" size="12"></td></tr>
    <tr><td>Tax Rate</td><td> <input name="taxrate" type="number" size="12"></td></tr>
    <tr><td>Taxes Paid</td><td> <input name="taxespaid" type="number" value="0" size="12"></td></tr>
    <tr><td>Refund or Due</td><td> <input name="refund" type="number" value="0" size="12"></td></tr>
    </table>
    <br>
    <br>
    <b>Extra Deductions
    Children <input name="stuff" checked type="radio">
    Spouse <input name="stuff" checked type="radio">
    Both <input name="stuff" checked type="radio">
    None <input name="stuff" checked type="radio">
    <br>
    <br>
    Over Age 65? <input name="over65" Checked type="checkbox">
    <br>
    <br>
    <input type="button" value="Calculate your Tax" onclick="calculate(this.form)">
    <input type="button" value="Clear Display Area" onclick="reset()">
    <br>
    <br>
    <b> Special Cases </b>
    <SELECT ID = Select1>
    <OPTION value = "Normal" >Normal</OPTION>
    <OPTION value = "Hardship Claimed" >Hardship Claimed</OPTION>
    <OPTION value = "Mercy" >Mercy</OPTION>
    <OPTION value = "Lawyer" >Lawyer</OPTION>
    </SELECT>

    <br>
    <br>
    <b>Your Text Rate</b>

    <br>
    <textarea name="yourtaxrate" rows="10" cols="30">
    </textarea>
    </form>
    </body>
    </html>

    However, you still need a place to display your asterisks, and you'll need to populate the rate.

    JoeUser on
  • Judge Joe BrownJudge Joe Brown Registered User regular
    edited March 2009
    Thanks you very much for the input. I've made a number of other corrections and I think I have everything working, time to turn her in with 40 minutes to spare!

    Judge Joe Brown on
  • SeguerSeguer of the Void Sydney, AustraliaRegistered User regular
    edited April 2009
    Just my OCD: Java =/= Javascript

    This may get you in trouble later on if you do an actual programming course.

    Also, you're passing the form into the method but aren't using it?

    Should also probably use <script type="text/javascript">

    Html attributes are better written attribute="value" or attribute='value' (just being pedantic)

    Seguer on
This discussion has been closed.