d2jsp
Log InRegister
d2jsp Forums > Off-Topic > Computers & IT > Programming & Development > Homework Assistance
Add Reply New Topic New Poll
Member
Posts: 12,702
Joined: Dec 28 2008
Gold: 11.01
Apr 23 2015 05:19am
I don't post here too much , but I am having a hard time figuring out this last bit of JavaScript

<html>
<script language="JavaScript">
function Calculate(value)
{
document.getElementById("ResponseDisplayArea").innerHTML="<h1>The answer is "+value
}
</script>
<form>
Enter a mathematical expression (e.g.- 2+2-3) and click the Evaluate button
<p><input type="text" name="expression"></p>
<input type="button" value="Evaluate" onClick=Calculate(expression.value)>
<input type="reset">
</form>
<div id="ResponseDisplayArea"></div>
</html>


I am trying to display the answer "The answer is ***" in the second division. Just cannot figure out how .
My results thus far have displayed "The answer is 2+2" the expression entered.
Member
Posts: 6,481
Joined: Jul 5 2009
Gold: 0.70
Apr 23 2015 09:39am
Quote (T_O_K_I_O @ Apr 23 2015 07:19am)
I don't post here too much , but I am having a hard time figuring out this last bit of JavaScript

<html>
<script language="JavaScript">
function Calculate(value)
{
document.getElementById("ResponseDisplayArea").innerHTML="<h1>The answer is "+value
}
</script>
<form>
Enter a mathematical expression (e.g.- 2+2-3) and click the Evaluate button
<p><input type="text" name="expression"></p>
<input type="button" value="Evaluate" onClick=Calculate(expression.value)>
<input type="reset">
</form>
<div id="ResponseDisplayArea"></div>
</html>


I am trying to display the answer "The answer is ***" in the second division. Just cannot figure out how .
My results thus far have displayed "The answer is 2+2" the expression entered.


You want the eval() function:

http://www.w3schools.com/jsref/jsref_eval.asp

eval("2 + 2") = 4

The answer is eval(value)
Member
Posts: 242
Joined: Jul 2 2014
Gold: Locked
Trader: Scammer
Jun 5 2015 01:15pm
I wish I knew about this part of d2jsp 2 months ago
Go Back To Programming & Development Topic List
Add Reply New Topic New Poll