Fixed:
<html>
<body>
<p>
this is a calculator simply enter the first number here
</p>
<input type="number" id="first"></input>
</body>
<p>
select the operation here
</p>
<button onclick="add()">+</button>
<button onclick="subtract()">-</button>
<button onclick="multiply()">*</button>
<button onclick="divide()">/</button>
<p>
put the seconed number here
</p>
<input type="number" id="seconed"></input>
<button onclick="run()">
perform
</button>
<button id="final" disabled="true">
this is where the answer is
</button>
</html>
<script>
var oper = 1;
function add(){
oper = 1;
}
function subtract(){
oper = 2;
}
function multiply(){
oper = 3;
}
function divide(){
oper = 4;
}
function run(){
var onenumber = document.getElementById("first").value
var twonumber = document.getElementById("seconed").value
if (oper == 1) {
// must use to string or else thinks you are concatenationg. So if #1= 3 and #2=4 it returns 34
var finalnum = Number(onenumber) + Number(twonumber)
}
if (oper == 2) {
var finalnum = onenumber - twonumber
}
if (oper == 3) {
var finalnum = onenumber * twonumber
}
if (oper == 4) {
var finalnum = onenumber / twonumber
}
document.getElementById("final").innerHTML = finalnum;
}
</script>
Whatever you want, though for game, take a look at p5 and p5play. I made a game using p5play. You can check out my code: Rolling Ball. Though for game dev I use unity.
Whatever you want, though for game, take a look at p5 and p5play. I made a game using p5play. You can check out my code: Rolling Ball. Though for game dev I use unity.