< Svelte

Svelte - Háromszög területe

Háromszög területe

src/routes/+page.svelte
<script>
let base = 0;
let height = 0;
let area = 0;
let enabled = false;
 
function onClickCalcButton() {
    enabled = true;
    area = calcTriangleArea();
}
 
function calcTriangleArea() {
    return base * height / 2;    
}
 
</script>
 
<h1>Háromszög területe</h1>
 
<div class="triForm">
    <div class="form-control">
        <label for="base">Alap</label>
        <input type="text" bind:value={base}>
    </div>
    <div class="form-control">
        <label for="height">Alap</label>
        <input type="text" bind:value={height}>
    </div>
 
    <button on:click={onClickCalcButton}>Számít</button>
 
    {#if enabled }
    <div class="form-control">
        <label for="area">Alap</label>
        <input type="text" bind:value={area}>
    </div>
    {/if}
 
</div>