Javascript for a prompt which accepts simple math as a value and then returns the answer
<blockquote>
  <p><strong>Possible Duplicate:</strong><br>
  <a href="http://stackoverflow.com/questions/2276021/evaluating-a-string-as-a-mathematical-expression-in-javascript">Evaluating a string as a mathematical expression in javascript</a>  </p>
</blockquote>



<p>I have written a snippet of code in javascript, for a prompt to appear when clicked. I want to be able to enter a simple math problem (i.e. 230/2) and have it output the answer, rather than the math problem I just entered. Your help will be much appreciated.</p>

<pre><code>&lt;!DOCTYPE html&gt;
&lt;html&gt;
&lt;body&gt;


&lt;button onclick="myFunction()"&gt;Click me&lt;/button&gt;

&lt;p id="demo"&gt;&lt;/p&gt;

&lt;script type="text/javascript"&gt;
function myFunction()
{
var x;

var mathProblem=prompt("Enter your math problem","");

if (name!=null)
  {
  x = mathProblem;
  document.getElementById("demo").innerHTML = x;
  }
}
&lt;/script&gt;

&lt;/body&gt;
&lt;/html&gt;
</code></pre>
