Community » Forum » Feedback » Developer Community

spacetinker
Businessman   VIP
i mean non-interactable boxes to make a website look good with designs
spacetinker
Businessman   VIP
is this good?:
<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>
<p id="final">
this is where the answer is
</p>
</html>
<script>
function = add(){
oper = 1;
}
function = subtract(){
oper = 2;
}
function = multiply(){
oper = 3;
}
function = divide(){
oper = 4;
}
function = run(){
onenumber = document.getElementById("first").value
twonumber = document.getElementById("seconed").value
if oper == 1 {
finalnum = onenumber + twonumber
}
if oper == 2 {
finalnum = onenumber - twonumber
}
if oper == 3 {
finalnum = onenumber * twonumber
}
if oper == 4 {
finalnum = onenumber / twonumber
}
document.getElementById("final").innerHTML = finalnum;
}
</script>
edit: okay it does not work i fixed the problem i found but it still does not work
spacetinker
Businessman   VIP
okay i revised some stuff and got this
<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>
function add(){
var oper = 1;
}
function subtract(){
var oper = 2;
}
function multiply(){
var oper = 3;
}
function divide(){
var oper = 4;
}
function run(){
var onenumber = document.getElementById("first").value
var twonumber = document.getElementById("seconed").value
if oper == 1 {
var finalnum = onenumber + 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>
masterplayer833
Businessman   VIP
Corrected and revised code:
<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 = toString(onenumber) + toString(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>
masterplayer833
Businessman   VIP
Admin does not want to share the codebase with people he does not know, so I told him that if he ever changes his mind we will be ready.
spacetinker
Businessman   VIP
i don't think that was the only problem
it's more of it won't return anything
masterplayer833
Businessman   VIP
It worked for me, are you using the code tester I gave you, because it does no seem to be working with scripts. Try pasting int into an HTML file and double clicking. For an editor try vscode.dev it works in browser.
spacetinker
Businessman   VIP
i was downloading the file then putting it in browser
masterplayer833
Businessman   VIP
It worked for me.
masterplayer833
Businessman   VIP
Maby look into the console. Pres ctrl shift I and select console. Press the buttons and then tell me what is in there.
First ... 8 9 10 11 12 ... Last