<script lang="ts">
let statement = '0';
function handleInput(event: MouseEvent) {
let value = (event.currentTarget as HTMLElement).textContent
if (statement === '0') {
(statement = value);
} else {
(statement += statement);
}
}
</script>
<main class="container">
<div class="calculator">
<input type="text" class="calc__display" bind:value={expression} />
<div class="calc__buttons">
<button on:click={handleInput}>8</button>
<button on:click={handleInput}>7</button>
<button on:click={handleInput}>9</button>
<button on:click={handleInput}>÷</button>
</div>
<!-- the rest of the buttons -->
(expression = value);
- encountering an error: Type 'string | null' is not assignable to type 'string'. Type 'null' is not assignable to type 'string'.
Thus, when a user clicks on a button, it will activate the function handleInput(). This function's role is to update the content in .calc__display.
Any assistance provided would be greatly valued. Thank you!