Calculator.html
Don't use plagiarized sources. Get Your Custom Essay on
Question: Have a part of the page for "Result", which, when the submit button is pressed, fills in the nume……
Get an essay WRITTEN FOR YOU, Plagiarism free, and by an EXPERT!
![head> title>Simple Calculator</title> script type-text/javascript> alert(This is a Javascript Calculator); function compute() var firstval-document.getElementById(firstval).value; var secondval-document.getElementById(secondval).value; firstval-Number(firstval); secondval-Number (secondval); var operation document.getElementsByName( operation); var result; for(var i-0; i < operation.length; i+)0 if (operation[i].checked){ if(operation[i].valueadd)fresult-firstval+secondval;} else if(operation[i].valuesub )Iresult-firstval-secondval;) else if(operation[i].valuemul)Iresult-firstval*secondval;) else if(operation[i].value -div)(result-firstval/secondval;]h document.getElementById(res).innerHTML-result; </script> 〈/head〉](https://media.cheggcdn.com/media%2F9c9%2F9c9d9a2e-d223-4bcc-b503-d6c645632057%2FphpYGV0cH.png)

Output:

Code in text format:
<!DOCTYPE html>
<html>
<head>
<title>Simple Calculator</title>
<script type=”text/javascript”>
alert(“This is a Javascript Calculator”);
function compute(){
var firstval=document.getElementById(“firstval”).value;
var secondval=document.getElementById(“secondval”).value;
firstval=Number(firstval);
secondval=Number(secondval);
var operation = document.getElementsByName(‘operation’);
var result;
for(var i = 0; i < operation.length; i++){
if(operation[i].checked){
if(operation[i].value==”add”){result=firstval+secondval;}
else if(operation[i].value==”sub”){result=firstval-secondval;}
else if(operation[i].value==”mul”){result=firstval*secondval;}
else if(operation[i].value==”div”){result=firstval/secondval;}
document.getElementById(“res”).innerHTML=result;
}
}
}
</script>
</head>
<body>
<h1>Simple Calculator</h1>
<table>
<tr>
<td style=”padding-top:50px;”>First value: <input type=”text” id=”firstval”></td>
<td>
<ul style=”border:2px solid black;list-style-type:none;padding:0px;width:40px;”>
<li>+ <input type=”radio” name=”operation” value=”add”></li>
<li>- <input type=”radio” name=”operation” value=”sub”></li>
<li>X <input type=”radio” name=”operation” value=”mul”></li>
<li>% <input type=”radio” name=”operation” value=”div”></li>
</ul></td>
<td style=”padding-top: 50px;”>Second value: <input type=”text” id=”secondval”></td>
<td style=”padding-top: 50px;”><input type=”button” onclick=”compute()” value=”Compute”></td>
</tr>
<tr>
<td colspan=”4″>
<p>Result: <span id=”res”></span></p>
</td>
</table>
</body>
</html>