I'm trying to dynamically create a 5 divs with a li using {each} in Svelte.
The code below renders the divs and lis but runs the calculate only once and hence gives the same result on each div/li:
let price;
let numberOfYears = 5;
function calculate() {
price = price * 1.04;
}
<form action="">
<label for="price">Price: </label>
<input type="number" bind:value={price} id="price" name="price" />
<button class="calculate" on:click={calculate}>Calculate</button>
{#each { length: numberOfYears } as _, i}
<div style="float: left; width: 19%; border: 1px solid #000000;">
<h2>Year 1</h2>
{calculate()}
<ul>
<li>{price}</li>
</ul>
</div>
{/each}
What I'm after is 5 years with incremental price (price * 1.04)