// Define the application const App = { template: `

Calculator

Use this calculator to perform basic arithmetic operations.

`, data() { return { display: 0, newNum: '', selectedOperation: '', previousOperation: '', result: '' }; }, methods: { calculateAndUpdateDisplay() { if (this.selectedOperation === '') return; if (this.newNum === '') return; if (this.previousOperation === '+') { this.result = this.display + parseInt(this.newNum); } else if (this.previousOperation === '-') { this.result = this.display - parseInt(this.newNum); } else if (this.previousOperation === '*') { this.result = this.display * parseInt(this.newNum); } else if (this.previousOperation === '/') { this.result = this.display / parseInt(this.newNum); } this.display = this.result; this.newNum = ''; }, clearAll() { this.display = 0; this.newNum = ''; this.selectedOperation = ''; this.previousOperation = ''; this.result = ''; }, clearNewNum() { this.newNum = ''; }, addDecimal() { if (this.newNum === '') return; this.newNum = `${this.newNum}.`; } } }; // Initialize the calculator component const calculator = Daisy.component({ template: `
` });