Several errors I am afraid. You need to revise your understanding of if...else (not if...then). And include more user input validation.
This ought to move you forward. Please study it and
learn from it. It is not really in your best interests that others do your all or most homework for you. Your teacher may gain a false and exaggerated idea of your programming capabilities and so not offer you the support you need. Also, if you hand in other people's work which you do not completely understand, then you will start to fall behind and your difficulties will increase.
Code:
<html>
<head>
</head>
<body >
<form name = "form1" action = "">
<h3>Number of people (1-60): <input type="text" name="numPeople" size ="2" maxlength = "2"></h1>
<h3>Select number of courses required</h3>
<input type="radio" name="course" value="1" /> One Course
<input type="radio" name="course" value="2" /> Two Course
<br /><br />
<input type="button" value="Submit Quote" onclick="checkForm()"/>
<input type="reset" value="Reset Quote"/>
<h3>Total Cost: <input type="text" name="tlcost" size="6" readonly;</h3>
</form>
<script type="text/javascript">
function checkForm() {
var people = Number(document.form1.numPeople.value) || 0; // 0 if NaN entered
if ((people <= 0) || (people >60)) {
alert ("You must enter a number from 1 to 60");
document.form1.numPeople.value = ""; // clear the field
return false; // go no further
}
var c= 0;
var f = document.form1.course; // avoid repetition
for (var i =0; i < f.length; i++) { // loop through the radio buttons to determine which one checked
if (f.course[i].checked) {
c = f.course[i].value; // 1 or 2, not "one or "two" as you want to use this value in a subsequent calculation
}
}
if (c ==0) { // no radio selected
alert ("You must select one or two courses");
return false;
}
var tot = 0;
// Now do your calculations of cost-per-head based on people and courses to arrive at the total cost
// I don't understand why the cost per head is greater if the number of people is over 30.
document.form1.tlcost.value = tot.toFixed(2);
}
</script>
</head>
<body>
</html>
A tip is to use the shortest names for functions and variables which are still meaningful/comprehensible, not something like btncheckform_onclick which is unwieldy and prone to typing errors. Rather than using underscores _ it is prefered to use camelCase.
It is recommended that you place the opening brace following the function, if, else, for, while, do, switch, and try statements on the
same line and not on the following line. Apart from that every Javascript statement should be followed by a semi-colon (;). It is quite possible to disregard this advice, but if you do one day it will rise up and bite you in the undercarriage.
BTW, when posting here please help us to help you by following the posting guidelines and wrapping your code in CODE tags. This means use the octothorpe or # button on the toolbar. You can (and should) edit your previous post.
"If you can't explain it simply, you don't understand it well enough”
“Everything should be as simple as it is, but not simpler.”
- both quotes Albert Einstein (German born American Physicist who developed the special and general theories of relativity. Nobel Prize for Physics in 1921. 1879-1955)