This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
npm login |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#performCalculation(): void { | |
const displayQuery = this.query.replace('÷', '/').replace('x', '*'); | |
const answer: number = eval(displayQuery); | |
const formattedAnswer = +parseFloat(answer.toString()).toFixed(2); | |
this.query = formattedAnswer.toString(); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public set query(value: string) { | |
this.#query = value; | |
+ this.#updateDisplay(); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#updateDisplay(): void { | |
if (this.#display === null) { | |
return; | |
} | |
this.#display.innerText = this.query; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#performCalculation(): void { | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
protected connectedCallback(): void { | |
this.#setEventListeners(); | |
} | |
protected disconnectedCallback(): void { | |
this.#unsetEventListeners(); | |
} | |
#setEventListeners(): void { | |
this.#buttons.forEach((button) => { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Calculator extends HTMLElement { | |
+ #display: HTMLElement | null = null; | |
+ #buttons: HTMLButtonElement[] = []; | |
+ #query = ''; | |
+ public get query(): string { | |
+ return this.#query; | |
+ } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
body { | |
background: darkgray; | |
} | |
.calculator { | |
display: block; | |
height: 440px; | |
width: 300px; | |
margin-top: 10%; | |
margin-left: auto; |