I started learning JS 2 days ago. I downloaded an algebra calculator and inserted it into my webpage. Here is the full code:
<!doctype html>
<html>
<head>
<div style="width:100%;">
<textarea id="output1" name="terminal" rows="4" cols="80" style="width:100%;"></textarea>
<input name="execute" value="▶" onclick="execute(1);" type="button">
</div>
<script src="javascripts/jquery.min.js"></script>
<script src="dist/latest-stable/algebrite.bundle-for-browser.js"></script>
<script type="text/javascript" language="javascript">
function execute (whichTerminal) {
var sandbox = $('sandbox');
var jsResult = $('jsResult');
try {
var textToBeExecuted = 'factor(3+3)';
var result;
if (/Algebrite\.[a-z]/.test(textToBeExecuted) || /;[ \t]*$/.test(textToBeExecuted)) {
result = eval(textToBeExecuted);
}
else {
result = Algebrite.run(textToBeExecuted);
}
//alert(result);
$('#output' + whichTerminal).val(result)
}
catch (err) {
var errDesc = err;
errorBox.update('<h4>Error!<\/h4><code>' + errDesc + '<\/code>' );
errorBox.show();
}
}
</script>
The script returns prime factors of 3+3 or 6 (var textToBeExecuted = 'factor(3+3)'
), but what I need is to evaluate expressions taken from the URL (example: /?input=3%B54
means 3+4 and returns 7). How can I do this? Please help!