3 Replies - 1304 Views - Last Post: 09 December 2009 - 09:39 PM

#1 biohobo  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 01-December 09

Grade Calculator Projcet Help Please

Posted 09 December 2009 - 06:08 PM

Ok..
this is my first post on this forum, so please excuse any mistakes i make.

Anyways, I am trying to finish my javascript project that calculates a semester grade for a single class.

I have been working on this for quite a while and i am on the last step of finishing.

Everything in this code works fine, but I do not know how to get the "homeNumber" "projNumber" and "examNumber" in the orinigal functions to carry down into my final function. Without this step, my final calculation is always NaN. Please Help :/

 
</head>
<body>

	  <script type="text/javascript">
	  <!--


/* Read in the homework grade from the user */

	function getHomework(lowerNum, upperNum, homeScore, homeNumber)
	{
	var i;
	var g = 0;
	

	   homeNumber = parseFloat(prompt("Please enter number of homework:"));
	   homeScore = new Array(homeNumber)
	   for(i = 0; i < homeNumber; i++)
		 {
	   g = (g + 1)
	
	   while (homeScore[i] < lowerNum || homeScore[i] > upperNum || isNaN(homeScore[i]))
	   {
 	   homeScore[i] = parseInt(prompt("Enter homework " + g + " score:"));
	   if (homeScore[i] < lowerNum || homeScore[i] > upperNum || isNaN(homeScore[i]))
			   {
				  alert("Please enter valid numbers. (0 to 105)");
			   }
		}
		   }
	return homeScore
	return homeNumber
	}



/* Read in the project grade from the user */

	function getProject(lowerNum, upperNum, projScore, projNumber)
	{
	var a;
	var b = 0;
	

	   projNumber = parseFloat(prompt("Please enter number of project:"));
	   projScore = new Array(projNumber)
	   for(a = 0; a < projNumber; a++)
		 {
	   b = (b + 1)
	
	   while (projScore[a] < lowerNum || projScore[a] > upperNum || isNaN(projScore[a]))
	   {
 	   projScore[a] = parseInt(prompt("Enter project " + b + " score:")); 
	   if (projScore[a] < lowerNum || projScore[a] > upperNum || isNaN(projScore[a]))
			   {
				  alert("Please enter valid numbers. (0 to 105)");
			   }
		}
		   }
	return projScore
	return projNumber
	}



/* Read in the exam grade from the user */

	function getExam(lowerNum, upperNum, examScore, examNumber)
	{
	var c;
	var d = 0;
	

	   examNumber = parseFloat(prompt("Please enter number of exam:"));
	   examScore = new Array(examNumber)
	   for(c = 0; c < examNumber; c++)
		 {
	   d = (d + 1)
	
	   while (examScore[c] < lowerNum || examScore[c] > upperNum || isNaN(examScore[c]))
	   {
 	   examScore[c] = parseInt(prompt("Enter exam " + d + " score:"));
	   if (examScore[c] < lowerNum || examScore[c] > upperNum || isNaN(examScore[c]))
			   {
				  alert("Please enter valid numbers. (0 to 105)");
			   }
		}
		   }
	return examScore
	return examNumber
	}

/* Calculating the average */

	function getAverage()
	{
	var finalHome;
	var finalProj;
	var finalExam;
	var finalGrade;
	var homeScore;
	var projScore;
	var examScore;
	var homeNumber = 1;
	var projNumber = 1;
	var examNumber = 1;
	var homeMulti;
	var projMulti;
	var examMulti;
	
	homeScore = getHomework(0,105,homeScore,homeNumber);
	projScore = getProject(0,105,projScore,projNumber);
	examScore = getExam(0,105,examScore,examNumber);
	document.write(examScore);
	document.write(examNumber)

	homeMulti = (.12 / homeNumber);
	projMulti = (.28 / projNumber);
	examMulti = (.60 / examNumber);
	
	document.write(examMulti);
	
	finalHome = (homeScore * homeMulti);
	finalProj = (projScore * projMulti);
	finalExam = (examScore * examMulti);
	finalGrade = (finalHome + finalProj + finalExam);
	document.write(finalExam);

	  if(finalGrade > 89.51)
 	  {
		document.write("<p>Your final letter grade in the class is an A.</p>");
	  }
	  else if(89.51 > finalGrade && finalGrade > 79.51)
 	  {
		document.write("<p>Your final letter grade in the class is a B.</p>");
	  }
	  else if(79.51 > finalGrade && finalGrade > 69.51)
 	  {
		document.write("<p>Your final letter grade in the class is a C.</p>");
	  }
	 	  else if(69.51 > finalGrade && finalGrade > 59.51)
 	  {
		document.write("<p>Your final letter grade in the class is a D.</p>");
	  }
		  else if(59.51 > finalGrade && finalGrade > 0)
		 {
		document.write("<p>Your final letter grade in the class is an F.</p>");
	  }
		 else
 	  {
		document.write("<p>Your final letter grade in the class is not avaliable.</p>");
	  }
	}

	getAverage()
	  -->
	  </script>
   </head>



Is This A Good Question/Topic? 0
  • +

Replies To: Grade Calculator Projcet Help Please

#2 JMRKER  Icon User is offline

  • D.I.C Addict

Reputation: 125
  • View blog
  • Posts: 818
  • Joined: 25-October 08

Re: Grade Calculator Projcet Help Please

Posted 09 December 2009 - 06:58 PM

Several problems to fix:

1. You have 2 </head> tags
2. Missing </body> and <html> tags
3. getAverage is never called in original script because of tag order
4. You cannot return 2 values from a function in this manner ...
	return homeScore
	return homeNumber


... in any of your functions.
5. The following ...
	homeScore = getHomework(0,105,homeScore,homeNumber);
	projScore = getProject(0,105,projScore,projNumber);
	examScore = getExam(0,105,examScore,examNumber);
	document.write(examScore);
	document.write(examNumber)

	homeMulti = (.12 / homeNumber);
	projMulti = (.28 / projNumber);
	examMulti = (.60 / examNumber);
  

... will set 'homeScore', 'projScore', and 'examScore'
but you will leave 'examNumber','projNumber', and 'homeNumber'
as undefined.

Put in some temporary alert messages after a calculation to see that the results of the calculation are correct.

If using FF, check the 'error console' output.

BTW: Welcome to the forum. :)

This post has been edited by JMRKER: 09 December 2009 - 07:00 PM

Was This Post Helpful? 0
  • +
  • -

#3 biohobo  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 01-December 09

Re: Grade Calculator Projcet Help Please

Posted 09 December 2009 - 07:17 PM

View PostJMRKER, on 9 Dec, 2009 - 05:58 PM, said:

Several problems to fix:

1. You have 2 </head> tags
2. Missing </body> and <html> tags
3. getAverage is never called in original script because of tag order
4. You cannot return 2 values from a function in this manner ...
	return homeScore
	return homeNumber


... in any of your functions.
5. The following ...
	homeScore = getHomework(0,105,homeScore,homeNumber);
	projScore = getProject(0,105,projScore,projNumber);
	examScore = getExam(0,105,examScore,examNumber);
	document.write(examScore);
	document.write(examNumber)

	homeMulti = (.12 / homeNumber);
	projMulti = (.28 / projNumber);
	examMulti = (.60 / examNumber);
  

... will set 'homeScore', 'projScore', and 'examScore'
but you will leave 'examNumber','projNumber', and 'homeNumber'
as undefined.

Put in some temporary alert messages after a calculation to see that the results of the calculation are correct.

If using FF, check the 'error console' output.

BTW: Welcome to the forum. :)



ok.. i fixed everything...
but for the last thing you said, i already knew that it was wrong.
I just do not know how to fix it.
Can you help?
Was This Post Helpful? 0
  • +
  • -

#4 JMRKER  Icon User is offline

  • D.I.C Addict

Reputation: 125
  • View blog
  • Posts: 818
  • Joined: 25-October 08

Re: Grade Calculator Projcet Help Please

Posted 09 December 2009 - 09:39 PM

View Postbiohobo, on 9 Dec, 2009 - 06:17 PM, said:

...

ok.. i fixed everything...
but for the last thing you said, i already knew that it was wrong.
I just do not know how to fix it.
Can you help?


Assuming the "last thing" was about the double return ...

Break the functions so that only ONE value is returned from a function.
(Will need to add some functions) and call each separately to have
an appropriate value returned for the next calculation.

BTW: There is a way to return 2 values from one function,
but it is above your pay grade at this time and I think
it would only confuse you. Better to break into two functions now.

Also: With major changes, you should re-post your code so that we
can be sure that we are talking about the same problems.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1