finished calculator project#13
Conversation
| <button class="number" id="number-7">7</button> | ||
| <button class="number" id="number-8">8</button> | ||
| <button class="number" id="number-9">9</button> | ||
| <button class="number" data-value="7" id="number-7">7</button> |
There was a problem hiding this comment.
Why do you need this property ?
| <button id="subtract">-</button> | ||
| <button id="multiply">*</button> | ||
| <button id="divide">/</button> --> | ||
| <button data-value="+" id="add">+</button> |
There was a problem hiding this comment.
Same question in here, why are you using it?
| @@ -0,0 +1,66 @@ | |||
| const display = document.querySelector(".display"); | |||
| let reset = true; | |||
There was a problem hiding this comment.
reset sounds like a function, maybe call this isReseted or something that will indicate the current state
| let reset = true; | ||
|
|
||
| const calculate = () => { | ||
| let result = 0; |
There was a problem hiding this comment.
Result could be global variable (global for this file) so you will not create it every time again and again
| display.textContent = result; | ||
| } | ||
| if (fulleq.includes("-")){ | ||
| let minieq = fulleq.split("-"); |
There was a problem hiding this comment.
You have 4 pieces of the same code, maybe extract it to function? the only different thing between them is the operator
| } | ||
| if (fulleq.includes("-")){ | ||
| let minieq = fulleq.split("-"); | ||
| result = Number(minieq[0]); |
There was a problem hiding this comment.
This could ne NAN, better add a check for it
| if (reset === true) { | ||
| display.textContent = btn.dataset.value; | ||
| reset = false; | ||
| } |
There was a problem hiding this comment.
If you will add return in here you will not need the else
|
|
||
| document.getElementById("clear").addEventListener("click", () => { | ||
| reset = true; | ||
| display.textContent = "0"; |
There was a problem hiding this comment.
Save your hardcoded strings into constant variables
No description provided.