Skip to content

Commit

Permalink
reworked bugs with operators
Browse files Browse the repository at this point in the history
- clicking 'C' with an operators works as expected
- cant enter multiple operators
  • Loading branch information
Kushagra J committed Nov 8, 2023
1 parent e4ce811 commit fde73f8
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions script/script.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,21 @@ function handleNumClick(){
return;
}
view.textContent += this.textContent;
clear.textContent = 'C';
if(clear.textContent != 'C'){
clear.textContent = 'C';
}
}

function handleOperationClick(){
if (view.textContent.slice(-1) == ' ') {
view.textContent = view.textContent.slice(0,-3);
view.textContent += ` ${this.textContent} `;
return;
}
view.textContent += ` ${this.textContent} `;
clear.textContent = 'C';
if(clear.textContent != 'C'){
clear.textContent = 'C';
}
}

function handleClearClick(){
Expand All @@ -49,6 +58,9 @@ function handleClearClick(){
if (view.textContent.length == 1) {
view.textContent = 0;
return;
} else if (view.textContent.slice(-1) == ' ') {
view.textContent = view.textContent.slice(0,-3);
return;
}
view.textContent = view.textContent.slice(0,-1);
}
Expand Down

0 comments on commit fde73f8

Please sign in to comment.