Skip to content

Instantly share code, notes, and snippets.

@WesleySmits
Created October 16, 2021 08:57
Show Gist options
  • Save WesleySmits/3730352b475d3ad51add86074a257a4b to your computer and use it in GitHub Desktop.
Save WesleySmits/3730352b475d3ad51add86074a257a4b to your computer and use it in GitHub Desktop.
Simple web calculator: Added special button event handling
#handleButtonClick(event: Event): void {
const target = event.target as HTMLButtonElement;
if (target === null) {
return;
}
const { value } = target;
const userValue = target.innerText;
+ switch (value) {
+ case 'ac':
+ this.query = '';
+ break;
+ case 'ce':
+ this.query = this.query.slice(0, -1);
+ break;
+ case '=':
+ this.#performCalculation();
+ break;
+ default:
+ this.query += userValue;
+ }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment