Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to import the Deno Deploy runtime API.
Deno
import { [1] } from "https://deno.land/x/deploy/mod.ts";
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'fetch' instead of 'serve' to start the server.
Trying to import 'listen' which is not part of Deno Deploy API.
✗ Incorrect
The 'serve' function is imported from Deno Deploy to handle HTTP requests at the edge.
2fill in blank
mediumComplete the code to respond with 'Hello from the edge!' to every request.
Deno
serve(() => new Response("[1]"));
Attempts:
3 left
💡 Hint
Common Mistakes
Using generic greetings that don't mention 'edge'.
Leaving the response empty.
✗ Incorrect
The response text 'Hello from the edge!' shows the code runs at the edge.
3fill in blank
hardFix the error in the code to correctly handle the request event.
Deno
addEventListener("fetch", event => { event.[1](new Response("Edge computing!")); });
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'request' instead of 'respondWith'.
Using 'reply' which is not a valid method.
✗ Incorrect
The 'respondWith' method is used on the event to send the response asynchronously.
4fill in blank
hardFill both blanks to create a simple edge handler that returns JSON with a message and status.
Deno
serve(() => {
const body = JSON.stringify({ message: "[1]" });
return new Response(body, { status: [2] });
});Attempts:
3 left
💡 Hint
Common Mistakes
Using status 404 which means not found.
Using a message unrelated to Deno Deploy.
✗ Incorrect
The message is a greeting from Deno Deploy and status 200 means success.
5fill in blank
hardFill all three blanks to create a handler that reads a query parameter 'name' and responds with a personalized greeting or a default message.
Deno
serve(request => {
const url = new URL(request.url);
const name = url.searchParams.get("[1]") || "[2]";
return new Response(`Hello, [3]!`);
});Attempts:
3 left
💡 Hint
Common Mistakes
Using 'username' instead of 'name' as the query parameter.
Not using template string syntax for the greeting.
✗ Incorrect
The query parameter is 'name', default is 'guest', and the greeting uses the variable 'name' inside a template string.
