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


Nilsp
11-09-2003, 11:03 AM
Hello
I am looking for a math script: a+b*x=y
where the user can choose x between 1-100 and get y result
I am studying at KTH in Stockhol Sweden and I am working on a chapter on functions in a math book for students aged 15.
Nils

Nayias
11-09-2003, 12:06 PM
<head>
<script language="JavaScript">
function calculate()
{
var x= prompt("Type a numbet between 1 and 100","0");
if(x>100 || x<0){
alert("invalid input"); calculate()
}
var a = 10;
var b = 20;
var y = a+b*x;
document.YourFormName.ynumber.value=y;
}
</script>
</head>

<body>
<form name="YourFormName">
<input type="button" value="Click her to choose an x number" onClick="calculate()"><br>
a=10<br>
b=20<br>
a+b*x=<br>
<input type="tekst" name="ynumber">
</form>
</body>


is that what you need?

Shampie
11-09-2003, 06:52 PM
Just a small reminder, as in math rules:
a+b*x=y b*x will be calculated first then a will be added.

(a+b)*x = y a and b will be added and multiplied by x.

if you wish to use a method to round the number to a full number use the Math.round(a+b*x) function.

Nilsp
11-14-2003, 04:48 AM
Hello
That was what I was looking for, thanks!
As the script is for the student to learn how to use functions, there is an additional script I need:
The previous script has generated an answer: a Y value, the student has to do the calculations and come up with the answer.
I need a script that when the answer frrom the student matches the correct Y value generated by the program the value is true, otherwise false and the student has to try again...
Regards Nils