Kevin Powell - CommunityKP-C
Kevin Powell - Community2y ago
6 replies
CDL

svelte logic (if else) - can you write this in the js? (potential very dumb question)

Basically I want to put a conditional in here so if count is == 0 then the decrement button vanishes (haven’t coded it as on phone).. I figured that’d be a conditional in the decrement function, and if it is do I write it as a typical js conditional, or a svelte conditional?

’js

<script>
let count = 0;

function increment() {
count += 1;
}
</script>

<button on:click={increment}>
Clicked {count}
{count === 1 ? 'time' : 'times'}
</button>

{#if count > 10}
<p>{count} is greater than 10</p>
{:else}
<p>{count} is between 0 and 10</p>
{/if}’js
Was this page helpful?