/    Sign up×
Community /Pin to ProfileBookmark

math script

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

to post a comment
JavaScript

3 Comments(s)

Copy linkTweet thisAlerts:
@NayiasNov 09.2003 — <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?
Copy linkTweet thisAlerts:
@ShampieNov 10.2003 — 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.
Copy linkTweet thisAlerts:
@NilspauthorNov 14.2003 — 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
×

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.17,
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,
)...