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
5 Replies
I've never worked with svelte but if it's like a templating engine then I would put the conditional to hide the button in svelte
Looks like you could do something like
I’ll check this out when home!
Idk if that'll work I was just going off of your syntax 😂
yea should work
Yep tested on the svelte tut and it works well. Thanks peeps. Now to understand form actions so I can build this app 😤