add stuff

This commit is contained in:
Adam 2024-01-12 08:03:49 -05:00
parent 047a92fdb5
commit 7e53fb499d
3 changed files with 159 additions and 0 deletions

90
calc.js Normal file
View file

@ -0,0 +1,90 @@
//----init----
//define shit
let total = 0;
let display = 0;
let last = 'init';
let store = 0;
let crumbs = [];
//on numIn
//write string to display
function updateDisplay(wit){
document.getElementById('display').innerText = parseFloat(wit);
}
function numIn(x) {
display = '' + display + x;
updateDisplay(display);
}
function del(){
display = 0;
updateDisplay(total);
}
function makeCrumbs(bread){
let crumb = 'nope';
switch (bread) {
case 'div':
crumb = '/';
break;
case 'mul':
crumb = '*';
break;
case 'sub':
crumb = '-';
break;
case 'add':
crumb = '+';
break;
case 'tot':
crumb = '=';
break;
case 'exp':
crumb = '^';
}
crumbs.push(parseFloat(display));
crumbs.push(crumb);
document.getElementById('breadcrumbs').innerText = crumbs.join(' ');
}
//on oprIn
function calcOp(opr) {
//convert display string to float
let input = parseFloat(display);
//update breadcrumbs
makeCrumbs(opr);
//copy display to store
store = parseFloat(display);
//if init copy display to total and update last
if (last == 'init'){
total = parseFloat(display);
}
//do math
switch(last){
case 'div':
total = total / parseInt(display);
break;
case 'mul':
total = total * parseInt(display);
break;
case 'sub':
total = total - parseInt(display);
break;
case 'add':
total = total + parseInt(display);
break;
case 'exp':
total = total ** parseInt(display);
break;
}
//clear display and show total, set last
del();
last = opr;
//logs
console.log(store);
console.log(total);
console.log(last);
console.log(typeof store);
console.log(typeof total);
}

38
index.html Normal file
View file

@ -0,0 +1,38 @@
<html>
<head>
<link rel='stylesheet' type='text/css' href="main.css">
<script src='calc.js'></script>
</head>
<body>
<div id='main'>
<textarea id='display'>0</textarea><br>
<textarea id='breadcrumbs'></textarea>
<button id='CD' onclick='location.reload(); return false;'>CLR</button>
<button id='CD' onclick='del()'>DEL</button>
<button onclick='calcOp("div")'>/</button>
<button onclick='calcOp("mul")'>*</button>
<br>
<button onclick='numIn(7)'>7</button>
<button onclick='numIn(8)'>8</button>
<button onclick='numIn(9)'>9</button>
<button onclick='calcOp("sub")'>-</button>
<br>
<button onclick='numIn(4)'>4</button>
<button onclick='numIn(5)'>5</button>
<button onclick='numIn(6)'>6</button>
<button onclick='calcOp("add")'>+</button>
<br>
<button onclick='numIn(1)'>1</button>
<button onclick='numIn(2)'>2</button>
<button onclick='numIn(3)'>3</button>
<button onclick='calcOp("tot")'>=</button>
<br>
<button onclick='numIn(0)'>0</button>
<button onclick='numIn("00")'>00</button>
<button onclick='numIn(".")'>.</button>
<button onclick='calcOp("exp")'>^</button>
</div>
</body>
</html>

31
main.css Normal file
View file

@ -0,0 +1,31 @@
body {
background-color: #222;
}
button {
width: 25%;
height: 25%;
float: left;
background-color: black;
border-color: white;
color: white;
font-size: 40;
}
#CD {
font-size: 30;
}
textarea {
width: 100%;
background-color: black;
color: white;
text-align: right;
}
#display {
font-size: 40;
}
#breadcumbs {
font-size: 20;
}
#main {
width: 300px;
height: 300px;
}