SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Member
    Join Date
    Oct 2013
    Posts
    8
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    math part is wrong

    Could someone please help me with this. Please. It works until I try to use the extra 3 % on B,C,D, and so on. I can't figure out what is wrong.
    I am sure it is probably something small but I cannot find it. Thank You.
    Code:
    
    <!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/javascript; charset=iso-8859-1" />
    <title>Untitled Document</title>
    <script type="text/javascript"  >
    function check_grade()
    {
    	 var percent = document.gradeForm.percent.value;
    	 var percent = parseFloat(percent);
    	 var absences = document.gradeForm.absences.value;
    	 var absences = parseInt(absences);
    	
    		if (absences >= 5) 
    		{
    			document.gradeForm.comments.value = "You have an F because of excessive absentees";
    		}
    	    else if (percent >= 90 && percent <= 100 && absences <= 2)
    		{
    			document.gradeForm.comments.value = "You have gained 3% to your percent for having few absences.\n" +
    			"Your Grade: A, Your Percent:" +(percent * 1.03).toFixed(2);
    		}
    		else if (percent >= 90 && percent <= 100)
    			document.gradeForm.comments.value = "Your Grade: A, Your Percent:" + percent;
    		else if (percent <= 89.9 && percent  >= 80)
    		{
    			document.gradeForm.comments.value = "Your Grade: B, Your percent:" + percent;
    		}
    		else if (percent <= 89.9 && percent >= 80 && absences <= 2)
    		{
    			document.gradeForm.comments.value = "You have gained 3% to your percent for having few absences.\n" +
    			"Your Grade: B, Your Percent:" + (percent * 1.03).toFixed(2);
    		}
    		else if (percent <= 79.9 && percent >= 70)
    		{
    			document.gradeForm.comments.value = "Your Grade: C, Your Percent:" + percent;
    		}
    		else if (percent <= 79.9 && percent >= 70 && absences <= 2)
    		{
    			document.gradeForm.comments.value = "You have gained 3% to your percent for having few absences.\n" +
    			"Your Grade: C, Your Percent:" + parseInt(percent * 1.03).toFixed(2);
    		}
    		else if (percent <= 69.9 && percent >= 60)
    		{
    			document.gradeForm.comments.value = "Your Grade: D, Your Percent:" + percent;
    		}
    		else if (percent <= 69.9 && percent >= 60 && absences <= 2)
    		{
    			document.gradeForm.comments.value = "You have gained 3% to your percent for having few absences.\n" +
    			"Your Grade: D, Your Percent:" +(percent * 1.03).toFixed(2);
    		}
    		else 
    		{
    			document.gradeForm.comments.value = "I am sorry you have fail this semester.\n" +
    			"Your Grade: F, Your Percent:" + percent;
    		}
    		}
    </script>
    </head>
    
    <body>		
       <form name="gradeForm" action="#">
       <label for="absences">How many absences do you have?: </label><br />
       <input type="text" name="absences" /><br />
       <label for="percent">What is your grade percent? </label><br />
       <input type="text" name="percent" /><br />
       <textarea id="comments" rows = "5" cols = "20"></textarea>
        <input type="button" value="Check Grade" id="checkGradeButton"  onclick="check_grade()" />
      
    </form>
    </body>
    </html>

  2. #2
    SitePoint Member
    Join Date
    Oct 2013
    Posts
    8
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by plat View Post
    Could someone please help me with this. Please. It works until I try to use the extra 3 % on B,C,D, and so on. I can't figure out what is wrong.
    I am sure it is probably something small but I cannot find it. Thank You.
    Code:
    
    <!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/javascript; charset=iso-8859-1" />
    <title>Untitled Document</title>
    <script type="text/javascript"  >
    function check_grade()
    {
    	 var percent = document.gradeForm.percent.value;
    	 var percent = parseFloat(percent);
    	 var absences = document.gradeForm.absences.value;
    	 var absences = parseInt(absences);
    	
    		if (absences >= 5) 
    		{
    			document.gradeForm.comments.value = "You have an F because of excessive absentees";
    		}
    	    else if (percent >= 90 && percent <= 100 && absences <= 2)
    		{
    			document.gradeForm.comments.value = "You have gained 3% to your percent for having few absences.\n" +
    			"Your Grade: A, Your Percent:" +(percent * 1.03).toFixed(2);
    		}
    		else if (percent >= 90 && percent <= 100)
    			document.gradeForm.comments.value = "Your Grade: A, Your Percent:" + percent;
    		else if (percent <= 89.9 && percent  >= 80)
    		{
    			document.gradeForm.comments.value = "Your Grade: B, Your percent:" + percent;
    		}
    		else if (percent <= 89.9 && percent >= 80 && absences <= 2)
    		{
    			document.gradeForm.comments.value = "You have gained 3% to your percent for having few absences.\n" +
    			"Your Grade: B, Your Percent:" + (percent * 1.03).toFixed(2);
    		}
    		else if (percent <= 79.9 && percent >= 70)
    		{
    			document.gradeForm.comments.value = "Your Grade: C, Your Percent:" + percent;
    		}
    		else if (percent <= 79.9 && percent >= 70 && absences <= 2)
    		{
    			document.gradeForm.comments.value = "You have gained 3% to your percent for having few absences.\n" +
    			"Your Grade: C, Your Percent:" + parseInt(percent * 1.03).toFixed(2);
    		}
    		else if (percent <= 69.9 && percent >= 60)
    		{
    			document.gradeForm.comments.value = "Your Grade: D, Your Percent:" + percent;
    		}
    		else if (percent <= 69.9 && percent >= 60 && absences <= 2)
    		{
    			document.gradeForm.comments.value = "You have gained 3% to your percent for having few absences.\n" +
    			"Your Grade: D, Your Percent:" +(percent * 1.03).toFixed(2);
    		}
    		else 
    		{
    			document.gradeForm.comments.value = "I am sorry you have fail this semester.\n" +
    			"Your Grade: F, Your Percent:" + percent;
    		}
    		}
    </script>
    </head>
    
    <body>		
       <form name="gradeForm" action="#">
       <label for="absences">How many absences do you have?: </label><br />
       <input type="text" name="absences" /><br />
       <label for="percent">What is your grade percent? </label><br />
       <input type="text" name="percent" /><br />
       <textarea id="comments" rows = "5" cols = "20"></textarea>
        <input type="button" value="Check Grade" id="checkGradeButton"  onclick="check_grade()" />
      
    </form>
    </body>
    </html>
    Never mind I got it figured out. Thank You

  3. #3
    SitePoint Guru
    Join Date
    Sep 2006
    Posts
    731
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Code:
    else if (percent <= 89.9 && percent  >= 80)
    		{
    			document.gradeForm.comments.value = "Your Grade: B, Your percent:" + percent;
    		}
    		else if (percent <= 89.9 && percent >= 80 && absences <= 2)
    		{
    If the if branch is entered then the else will not. The test for absences <= 2 could be done inside the if branch.
    Needless to say there are more efficient ways of doing this.
    Tab-indentation is a crime against humanity.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •