Click to See Complete Forum and Search --> : math script


Nilsp
11-28-2003, 05:09 AM
I need more help with a math script.
The function: a + b * x = y.
The teatcher enters for example a = 30 and b = 8.
The student can choose between 1-100 in the x field.
The script will compute the calculation and come up with an y answer.
The answer has to be hidden and the student has to figure out the y value.
When the calculation from the script matches the value the student has come up with the value is true or otherwise false and the student has to try again.
Thanks
Nils Pihlblad Stockholm Sweden

Gollum
11-28-2003, 05:30 AM
This might give you some pointers...

<html>
<head>
<script type="text/javascript">
function check()
{
var a = parseInt(document.f.a.value);
var b = parseInt(document.f.b.value);
var x = parseInt(document.f.x.value);
var y = parseInt(document.f.y.value);

if ( a + b * x == y ) alert("That's right!!!");
else
{
alert("No, try again");
document.f.y.focus();
}
}

</script>
<body>
<form name=f>
<table>
<tr>
<td><input type=text name=a></td>
<td>+</td>
<td><input type=text name=b></td>
<td>*</td>
<td><input type=text name=x></td>
<td>=</td>
<td><input type=text name=y></td>
<td><button onclick="check();">Check Answer</button>
</tr>
</table>
</form>
</body>
</html>

Nilsp
12-01-2003, 05:47 AM
Thanks!
This is of great help
Nils Stockholm Sweden

Gollum
12-01-2003, 06:15 AM
You're welcome :cool: