/    Sign up×
Community /Pin to ProfileBookmark

math script

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

to post a comment
JavaScript

3 Comments(s)

Copy linkTweet thisAlerts:
@GollumNov 28.2003 — This might give you some pointers...
<i>
</i>&lt;html&gt;
&lt;head&gt;
&lt;script type="text/javascript"&gt;
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();
}
}

&lt;/script&gt;
&lt;body&gt;
&lt;form name=f&gt;
&lt;table&gt;
&lt;tr&gt;
&lt;td&gt;&lt;input type=text name=a&gt;&lt;/td&gt;
&lt;td&gt;+&lt;/td&gt;
&lt;td&gt;&lt;input type=text name=b&gt;&lt;/td&gt;
&lt;td&gt;*&lt;/td&gt;
&lt;td&gt;&lt;input type=text name=x&gt;&lt;/td&gt;
&lt;td&gt;=&lt;/td&gt;
&lt;td&gt;&lt;input type=text name=y&gt;&lt;/td&gt;
&lt;td&gt;&lt;button onclick="check();"&gt;Check Answer&lt;/button&gt;
&lt;/tr&gt;
&lt;/table&gt;
&lt;/form&gt;
&lt;/body&gt;
&lt;/html&gt;
Copy linkTweet thisAlerts:
@NilspauthorDec 01.2003 — Thanks!

This is of great help

Nils Stockholm Sweden
Copy linkTweet thisAlerts:
@GollumDec 01.2003 — You're welcome ?
×

Success!

Help @Nilsp spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.19,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...