tutorial: move function declaration before reference (#5491)

pull/5559/head
Daniel Power 4 years ago committed by GitHub
parent 10f68289ba
commit 379a4454c1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -1,6 +1,4 @@
<script> <script>
let promise = getRandomNumber();
async function getRandomNumber() { async function getRandomNumber() {
const res = await fetch(`tutorial/random-number`); const res = await fetch(`tutorial/random-number`);
const text = await res.text(); const text = await res.text();
@ -12,6 +10,8 @@
} }
} }
let promise = getRandomNumber();
function handleClick() { function handleClick() {
promise = getRandomNumber(); promise = getRandomNumber();
} }
@ -22,4 +22,4 @@
</button> </button>
<!-- replace this element --> <!-- replace this element -->
<p>{promise}</p> <p>{promise}</p>

@ -1,6 +1,4 @@
<script> <script>
let promise = getRandomNumber();
async function getRandomNumber() { async function getRandomNumber() {
const res = await fetch(`tutorial/random-number`); const res = await fetch(`tutorial/random-number`);
const text = await res.text(); const text = await res.text();
@ -11,6 +9,8 @@
throw new Error(text); throw new Error(text);
} }
} }
let promise = getRandomNumber();
function handleClick() { function handleClick() {
promise = getRandomNumber(); promise = getRandomNumber();
@ -27,4 +27,4 @@
<p>The number is {number}</p> <p>The number is {number}</p>
{:catch error} {:catch error}
<p style="color: red">{error.message}</p> <p style="color: red">{error.message}</p>
{/await} {/await}

Loading…
Cancel
Save