Page 1 of 1

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

### #1 biohobo

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

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

```
<body>

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

{
var i;
var g = 0;

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]))
{
}
}
}
return homeScore
}

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]))
{
}
}
}
return projScore
return projNumber
}

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]))
{
}
}
}
return examScore
return examNumber
}

/* Calculating the average */

function getAverage()
{
var finalHome;
var finalProj;
var finalExam;
var homeScore;
var projScore;
var examScore;
var projNumber = 1;
var examNumber = 1;
var homeMulti;
var projMulti;
var examMulti;

projScore = getProject(0,105,projScore,projNumber);
examScore = getExam(0,105,examScore,examNumber);
document.write(examScore);
document.write(examNumber)

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);

{
}
{
}
{
}
{
}
{
}
else
{
}
}

getAverage()
-->
</script>

```

Is This A Good Question/Topic? 0

### #2 JMRKER

Reputation: 134
• Posts: 868
• Joined: 25-October 08

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

```

... 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)

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

### #3 biohobo

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

Posted 09 December 2009 - 07:17 PM

JMRKER, 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

```

... 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)

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?

### #4 JMRKER

Reputation: 134
• Posts: 868
• Joined: 25-October 08

Posted 09 December 2009 - 09:39 PM

biohobo, 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.