Initially, the code mentioned onClick
, however, it should be written as onclick
since it is case-sensitive.
Furthermore, the statement document.calculator.ans.value
is incorrect and will not function properly. The correct approach is to use ans.value
only, which should resolve the issue.
Below, you can find the HTML code for a calculator that will display the desired output (and it works)
body {
background-color: #FFFFFF;
background-size: 1500px;
}
#calculator {
width: 250px;
height: 375px;
text-align: center;
margin: 90px auto;
box-shadow: 10px 10px 10px #010012;
background-color: #229EE2;
background-size: 7px;
border-radius: 30px;
border: 3px solid #595959;
}
#display {
margin: 30px 0 20px 0;
padding-right: 2%;
width: 220px;
height: 30px;
border-radius: 4px;
box-shadow: 0px 0px 3px #595959;
text-align: right;
font: 27px bold;
color: #1A3C67;
background-color: #78c4ed;
}
#keys {
width: 43px;
height: 35px;
margin-left: 10px;
margin-bottom: 20px;
box-shadow: 0px 0px 15px #010012;
cursor: pointer;
font-style: italic;
color: lightblue;
background-color: rgb(0, 50, 68);
font-weight: bold;
font-size: 24px;
border-radius: 4px;
}
#keys:hover {
background: #1998cd;
font-weight: bold;
color: #1e185e;
}
#keysC {
width: 43px;
height: 35px;
margin-left: 10px;
margin-bottom: 20px;
box-shadow: 0px 0px 10px #595959;
cursor: pointer;
font-style: italic;
color: #1A3C67;
background-color: lightblue;
font-weight: bold;
font-size: 16px;
border-radius: 4px;
}
#keysC:hover {
background: #7caad0;
font-weight: bold;
color: #1A3C67;
}
<!DOCTYPE html>
<html>
<head>
<title>Financial Calculator</title>
<link rel="stylesheet" type="text/css" href="style123.css">
</head>
<body>
<div id="calculator">
<div class="fluid-container">
<form name="Financial Calculator">
<input type="text" id="display" name="ans" value="" class="form-control" placeholder="">
<br>
<div class="row">
<div>
<input type="reset" id="keysC" value="C">
<input type="reset" id="keysC" value="CE">
<input type="button" id="keysC" value="<--">
<input type="button" id="keysC" value="%" onclick="ans.value+='%'">
</div>
</div>
<br>
<input type="button" id="keys" value="7" onclick="ans.value+='7'">
<input type="button" id="keys" value="8" onclick="ans.value+='8'">
<input type="button" id="keys" value="9" onclick="ans.value+='9'">
<input type="button" id="keysC" value="/" onclick="ans.value+='/'">
<br>
<input type="button" id="keys" value="4" onclick="ans.value+='4'">
<input type="button" id="keys" value="5" onclick="ans.value+='5'">
<input type="button" id="keys" value="6" onclick="ans.value+='6'">
<input type="button" id="keysC" value="*" onclick="ans.value+='*'">
<br>
<input type="button" id="keys" value="1" onclick="ans.value+='1'">
<input type="button" id="keys" value="2" onclick="ans.value+='2'">
<input type="button" id="keys" value="3" onclick="ans.value+='3'">
<input type="button" id="keysC" value="-" onclick="ans.value+='-'">
<br>
<input type="button" id="keys" value="0" onclick="ans.value+='0'">
<input type="button" id="keys" value="." onclick="ans.value+='.'">
<input type="button" id="keys" value="=" onclick="ans.value=eval(ans.value)">
<input type="button" id="keysC" value="+" onclick="ans.value+='+'">
</form>
</div>
</div>
</body>
</html>