Heres what our objective is:
This project is designed to give you practice using arrays in Javascript.
The Task
You are going to make some improvements to the grade calculator that you designed in Project 1. Rather than storing each of the grades in individual variables, you are going to use arrays to store your data. You should have an array for each of the different types of grades: homeworks, projects and exams. You are also going to error check the user input. You should use the function GetValidNumberInput() that you used in Project 3. You should have a function Average() that takes an array and returns the average of all the elements in the array.
More Details
* You must use for loops when dealing with the arrays (i.e. when you are reading the grades in from the user.)
* Correction! The only two functions you are required to use are GetValidNumberInput() and Average(). If you would like to create and use other functions, you are more than welcome to do so.
* The valid range for grades is 0 to 105.
**There are 3 homeworks , 4 projects, 3 exams
Homework is 4% each
Proj is 7 % each
Exam is 20% each
-----------------------------------------------------------------------------------------------------------------------
Also if its not too much trouble to ask, my friend also needs help with his code. He's finished a rough copy and sent it to me to check out, I was going to post it here for everyone to take a look at if they could give him some tips.
(he doesnt have an account and I told him it wasn't necessary to make one)
Here's his code ///// Im halfway through making a rough copy of my code and I will post it in a bit.
<script type="text/javascript">
var hwArray = new array[3];
var prjArray = new array[4];
var examArray = new array[3];
var hwAvg = 0;
var prjAvj = 0;
var examAvj = 0;
For (int i=1; i=<3;i++){
hwArray [i] = GetValidNumberInput("Enter the Homework score", 0 , 100);
hwAvg = Avg(hw);
alert("The final average is" +hwAvg); }
For (int j=1; j=<4;j++){
prjArray [j] = GetValidNumberInput("Enter the Homework score", 0 , 100);
prjAvg = Avg(prj);
alert("he final average is" +prjAvg); }
For (int k=1; k=<3;k++){
examArray [k] = GetValidNumberInput("Enter the Homework score", 0 , 100);
examAvg = Avg(exam);
alert("The final average is" +examAvg); }
function Avg(nums)
{
Sum = 0;
for (int i = 0; i < nums.length; i++){
Sum += nums[i]
}
return Sum;
}
function GetValidNumberInput(promptString, lowerNum, upperNum)
{
var num = parseInt(prompt(promtString));
while(isNaN (num)|| num < lowerNum || num > upperNum)
{
alert(num + "is not an integer between "
+ lowerNum + "and " =upperNum);
num = parseInt(prompt(promptString));
}
return num;
}
here is the link to the homework site with full requirements and example screenshots
http://www.csee.umbc...ojects/p4.shtml
This post has been edited by cnampheonix: 15 December 2009 - 03:15 PM

New Topic/Question
Reply



MultiQuote







|