From 7e53fb499d0f61c1d884ff2d57434f53b9196f0e Mon Sep 17 00:00:00 2001 From: Adam <24621027+WhiteDopeOnPunk@users.noreply.github.com> Date: Fri, 12 Jan 2024 08:03:49 -0500 Subject: [PATCH] add stuff --- calc.js | 90 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ index.html | 38 +++++++++++++++++++++++ main.css | 31 +++++++++++++++++++ 3 files changed, 159 insertions(+) create mode 100644 calc.js create mode 100644 index.html create mode 100644 main.css diff --git a/calc.js b/calc.js new file mode 100644 index 0000000..591c57c --- /dev/null +++ b/calc.js @@ -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); +} + diff --git a/index.html b/index.html new file mode 100644 index 0000000..bf6b374 --- /dev/null +++ b/index.html @@ -0,0 +1,38 @@ + + + + + + +
+
+ + + + + +
+ + + + +
+ + + + +
+ + + + +
+ + + + +
+ + + + diff --git a/main.css b/main.css new file mode 100644 index 0000000..bbedb1c --- /dev/null +++ b/main.css @@ -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; +}