Skip to content

Instantly share code, notes, and snippets.

@cgrusden
Created December 27, 2020 14:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cgrusden/acff6927877940b7d3a46a2c8ed4021f to your computer and use it in GitHub Desktop.
Save cgrusden/acff6927877940b7d3a46a2c8ed4021f to your computer and use it in GitHub Desktop.
Svelte projects
<script>
let answer = '';
let answers = [
'It is certain',
'It is decidedly so',
'Without a doubt',
'Yes – definitely',
'You may rely on it',
'As I see it, yes',
'Most likely',
'Outlook good',
'Yes',
'Signs point to yes',
'Reply hazy, try again',
'Ask again later',
'Better not tell you now',
'Cannot predict now',
'Concentrate and ask again',
'Don\'t count on it',
'My reply is no',
'My sources say no',
'Outlook not so good',
'Very doubtful'
];
function handleClick() {
let randomNumber = Math.floor((Math.random() * answers.length) + 1);
answer = answers[randomNumber]
}
</script>
<button on:click={handleClick}>Ask the 8-Ball</button>
<p>Magic 8-Ball says</p>
{#if answer}
<h3>{answer}</h3>
{:else}
<h3>Ask yourself a question and then Hit the button!</h3>
{/if}
There are {answers.length} possible answers:
<ul>
{#each answers as anAnswer}
{#if anAnswer === answer}
<li><b>{anAnswer}</b></li>
{:else}
<li>{anAnswer}</li>
{/if}
{/each}
</ul>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment