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