PDA

View Full Version : Need Help- Marks and Grades weightings


Jason.K
08-15-2002, 02:27 AM
Hi,

I have just started JavaScript and I am doing a Web Production course and I have a test coming up next week. The test will be a similar program to the one below. Here is what we had to do for this program.

Validation

Name must be 2 tp 20 characters
The remainder must be a valid intefer between 0 and 100

Error message to appear in textarea

Max. Weights- assignments worth 40%, theory test 20%

Grade Calcuation

Fail if either

assignment 1 + assignment 2 is less than 50
theory test is less than 50
total marks is less than 50

Grade = pass if total marks is between 50 and less than 70
Grade = pass if total marks 50 or more and resit box checked
grade - credit if total marks between 70 or less than 83
grade = distinction if total marks between 83 and 100.

Here is the code I have so far:

<html>
<head>
<script lanuage="JavaScript">

function getName(txtName, txtMarks1, txtMarks2, txtTest, chkResit, txtResults)
{

var msg = ""
var name = txtName.value
if(name.length <2 || name.length >20)
{
msg= "Please enter another name"
txtResults.value = msg
txtName.focus()
}
else
{
var grade = ""
mark1 = parseInt(txtMarks1.value)
mark2 = parseInt(txtMarks2.value)
theory = parseInt(txtTest.value)

if(mark1 + mark2 <50)
{
grade = "Fail"
}
if(theory <50)
{
grade = "Fail"
}
if(mark1 + mark2 + theory <50)
{
grade = "Fail"
}
if(mark1 + mark2 + theory >50 <70)
{
grade = "Pass"
}
if(mark1 + mark2 + theory >50 && chkResit.checked)
{
grade = "Pass"
}
if(mark1 + mark2 + theory >70 <83)
{
grade = "Credit"
}
if(mark1+ mark2 + theory >83)
{
grade = "Distinction"
}

msg = "Results for " + name + "\n\nAssignment 1: " + txtMarks1.value + "\nAssignment2: " + txtMarks2.value + "\nTheory Test: " + txtTest.value + "\n\tGrade: " + grade
txtResults.value = msg
}
}

</script>
</head>
<body>
Subject Marks and Grade
<form>
<p>Student Name: <input type="text" name="txtName" value=""><br>
Assignment 1: <input type="text" name="txtMarks1" value="">%<br>
Assignment 2: <input type="text" name="txtMarks2" value="">%<br>
Theory Test: <input type="text" name="txtTest" value="">%
<input type="checkbox" name="chkResit" value="Resit">Resit
<p>Student Results<br><textarea name="txtResults" value="" rows="10" cols="50"></textarea><br>
<input type="button" value="Calcuate Marks" onClick="getName(txtName, txtMarks1, txtMarks2, txtTest, chkResit, txtResults)">
</form>
</body>
</html>

As you may of seen, it doesn't contain the weighting- assignments 40% each and theory test 20%. I am not sure how to do this and don't have a class before the test next week and need to know how to do this. If anyonbe can help it would be great.

Regards, Jason

x_goose_x
08-15-2002, 02:46 AM
You can't use:

if(mark1 + mark2 + theory >50 <70)

try:

if(mark1+mark2+theory>50&&mark1+mark2+theory<70)

Jason.K
08-15-2002, 02:50 AM
Ok thanks for that, do you know how to do the percentage weighting?

assignments worth 40% each of total mark and theory test worth 20% of total mark

Thanks, Jason

x_goose_x
08-15-2002, 03:09 AM
Also you don't need to do the double check:

if (mark>50&&mark<70)

you can just set it up like this:

if (mark>=90) {
grade = "A";
}
else if (mark>=80) {
grade = "B";
}
else if (mark>=70) {
grade = "C";
}
else if (mark>=60) {
grade = "D";
}
else if (mark<60) {
grade = "F";
}

Jason.K
08-15-2002, 03:18 AM
To add the weightings for assignments and theory test is it something easy to add or will I need to change all the code?

x_goose_x
08-15-2002, 03:22 AM
For the weighing it's pretty simple math.

mark1 = 75
mark2 = 83
test1 = 95

final = (mark1*0.2)+(mark2*0.2)+(test1*0.6);

Jason.K
08-15-2002, 04:35 AM
I have changed the code to the following:

<html>
<head>
<script lanuage="JavaScript">

function getName(txtName, txtMarks1, txtMarks2, txtTest, chkResit, txtResults)
{

var msg = ""
var name = txtName.value
if(name.length <2 || name.length >20)
{
msg= "Please enter another name"
txtResults.value = msg
txtName.focus()
}
else
{


mark1 = parseInt(txtMarks1.value)
mark2 = parseInt(txtMarks2.value)
theory = parseInt(txtTest.value)

final = (mark1*0.4)+(mark2*0.4)+(theory*0.2)


if(final <100)
{
grade = "Distinction"
}

if(final <83)
{
grade = "Credit"
}
if(final <70)
{
grade = "Pass"
}
if(final <50)
{
grade = "Fail"
}





msg = "Results for " + name + "\n\nAssignment 1: " + txtMarks1.value + "\nAssignment2: " + txtMarks2.value + "\nTheory Test: " + txtTest.value + "\n\tGrade: " + grade
txtResults.value = msg
}
}

</script>
</head>
<body>
Subject Marks and Grade
<form>
<p>Student Name: <input type="text" name="txtName" value=""><br>
Assignment 1: <input type="text" name="txtMarks1" value="">%<br>
Assignment 2: <input type="text" name="txtMarks2" value="">%<br>
Theory Test: <input type="text" name="txtTest" value="">%
<input type="checkbox" name="chkResit" value="Resit">Resit
<p>Student Results<br><textarea name="txtResults" value="" rows="10" cols="50"></textarea><br>
<input type="button" value="Calcuate Marks" onClick="getName(txtName, txtMarks1, txtMarks2, txtTest, chkResit, txtResults)">
</form>
</body>
</html>

I now what to know how to get the following with the weightings still being used.

A fail if:

Assignment 1 (mark1) + Assignment 2 (mark2) less than 50
Theory test (theory) is less than 50.

I can do it without using the weightings but need to use the weightings-

both assignments 40% each and theory test 20%

If I just say if(mark1 + mark 2 <50) it won't use the weightings.

I am sorry about this I am not very good with JavaScript.

Regards, Jason