Function inside math function
Ok, so I'm sure this has a simple solution, but I can't work it out and it's really bugging me!
I've got my code, and the task is to generate two random numbers, the user then inputs an answer for them added together, then the program checks the answer and displays either "correct" or "wrong"
Here's some of my code:
Code:
<HTML>
<TITLE>Assessment Task 3 : Rohan Gardiner</TITLE>
<HEAD>
<SCRIPT LANGUAGE ="JavaScript">
function maths()
{
var response;
var answer;
answer = document.questions.answer.value;
if (answer==document.adding)
{
response = "correct";
}
else
{
response = "wrong";
}
document.questions.result.value = response ;
}
function randoms()
{
rndNum = Math.random();
Num = rndNum*20;
Num1=rndNum*10
document.write(Math.round(Num)+"+"+ Math.round(Num1));
}
function adding()
{
document.write(Math.round(Num) + Math.round(Num1));
}
</SCRIPT>
</HEAD>
<BODY>
<h1 align="center">Rohan Gardiner Assessment Task 3</h1>
<FORM NAME = "questions">
<SCRIPT Language=JavaScript> randoms(); </script>
=
<INPUT TYPE = "textbox" NAME = "answer" > <BR>
<INPUT NAME = "dobutton" TYPE = "button" Value = "check" onClick= "maths()">
<INPUT TYPE = "textbox" NAME = "result" >
</BODY>
</HTML>
Yes, I am a noobie coder. Please help :(
Simple Math Equation Help Needed
I have two, dollar values (a and b). I need to divide the larger (max) into the smaller (min) and multiply by 100 to get the percentage difference (c value) for box3.
The following javascript is what I wrote into the Acrobat PDF (under calculations), but I get NaN instead of a number.
I've tried multiple variations, and tried researching this relatively simple equation to find code, but without finding or understanding what I need. I'm not a programmer and need help.
This is my best attempt:
var a=this.getField("Box1");
var b=this.getField("Box2");
var c=this.getField("Box3");
var d=Math.min(a,b);
var e=Math.max(a,b);
c.value=(e.value/d.value)*100;