Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to import a module in Deno.
Deno
import { serve } from "https://deno.land/std/http/server.ts"[1]
Attempts:
3 left
💡 Hint
Common Mistakes
Using a comma or period instead of a semicolon at the end of the import.
✗ Incorrect
In Deno, module imports end with a semicolon just like in JavaScript.
2fill in blank
mediumComplete the code to run a simple HTTP server in Deno.
Deno
const server = serve({ port: [1] });Attempts:
3 left
💡 Hint
Common Mistakes
Putting the port number in quotes, making it a string.
Using variable names instead of a number.
✗ Incorrect
The port number should be a number, not a string or variable name.
3fill in blank
hardFix the error in the Deno permission request code.
Deno
const status = await Deno.permissions.[1]({ name: "read" });
Attempts:
3 left
💡 Hint
Common Mistakes
Using
request instead of check causes the code to ask for permission instead of checking.✗ Incorrect
The check method is used to see if permission is already granted.
4fill in blank
hardFill both blanks to create a secure file read in Deno.
Deno
if (await Deno.permissions.[1]({ name: "read", path: "./data.txt" }).state === "granted") { const data = await Deno.[2]("./data.txt", { encoding: "utf-8" }); }
Attempts:
3 left
💡 Hint
Common Mistakes
Using
query instead of check for permissions.Using
writeFile instead of readTextFile to read files.✗ Incorrect
Use check to verify permission and readTextFile to read file content as text.
5fill in blank
hardFill all three blanks to create a Deno script that fetches JSON data securely.
Deno
const response = await fetch("https://api.example.com/data"); if (response.status === [1]) { const json = await response.[2](); console.[3](json); }
Attempts:
3 left
💡 Hint
Common Mistakes
Checking for status 404 or other codes instead of 200.
Using
text() instead of json() to parse response.Using
console.error instead of console.log to print.✗ Incorrect
Check for HTTP status 200, parse JSON with json(), and print with console.log.
