Complete the code to show a loading message while waiting for the promise.
<script> let dataPromise = fetch('/api/data').then(res => res.json()); </script> {#await [1] <p>Loading...</p> {/await}
The {#await} block waits for the promise dataPromise to resolve or reject.
Complete the code to display the resolved data inside the await block.
{#await dataPromise}
<p>Loading...</p>
{:then [1]
<p>{user.name}</p>
{/await}:then.:then.The :then block receives the resolved value, here named user.
Fix the error in the await block to handle errors properly.
{#await dataPromise}
<p>Loading...</p>
{:then user}
<p>{user.name}</p>
{:catch [1]
<p>Error: {error.message}</p>
{/await}:catch.The variable after :catch must match the one used inside the block, here error.
Fill both blanks to show a loading message and handle the resolved data.
{#await [1]
<p>Loading data...</p>
{:then [2]
<p>{info.title}</p>
{/await}The {#await} block waits for dataPromise. The resolved data is named info.
Fill all three blanks to handle loading, success, and error states in the await block.
{#await [1]
<p>Loading...</p>
{:then [2]
<p>{data.message}</p>
{:catch [3]
<p>Error: {err.message}</p>
{/await}The promise is messagePromise. The resolved data is data. The error variable is err.
