Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to read a file using Deno with the correct permission flag.
Deno
const data = await Deno.readTextFile('example.txt'); console.log(data); // Run with deno run [1] script.ts
Attempts:
3 left
💡 Hint
Common Mistakes
Using --allow-write instead of --allow-read
Forgetting to add any permission flag
Using network permission --allow-net by mistake
✗ Incorrect
To read files in Deno, you must run the script with the --allow-read flag to grant read permission.
2fill in blank
mediumComplete the code to write text to a file using Deno with the correct permission flag.
Deno
await Deno.writeTextFile('output.txt', 'Hello Deno!'); // Run with deno run [1] script.ts
Attempts:
3 left
💡 Hint
Common Mistakes
Using --allow-read instead of --allow-write
Not adding any permission flag
Confusing with network or run permissions
✗ Incorrect
Writing files requires the --allow-write permission flag in Deno.
3fill in blank
hardFix the error in the command to allow both reading and writing files.
Deno
deno run [1] script.tsAttempts:
3 left
💡 Hint
Common Mistakes
Using only one permission flag
Combining flags without space
Using unrelated permission flags
✗ Incorrect
To allow both reading and writing, you must include both flags: --allow-read and --allow-write.
4fill in blank
hardFill both blanks to correctly check if the script has read and write permissions.
Deno
const hasRead = await Deno.permissions.query({ name: '[1]' });
const hasWrite = await Deno.permissions.query({ name: '[2]' });Attempts:
3 left
💡 Hint
Common Mistakes
Using 'net' or 'run' instead of 'read' or 'write'
Mixing up the order of permissions
Using permission names with --allow- prefix
✗ Incorrect
The permission names for checking are 'read' and 'write' for file system access.
5fill in blank
hardFill all three blanks to request read permission, write permission, and then log if both are granted.
Deno
const readPerm = await Deno.permissions.request({ name: '[1]' });
const writePerm = await Deno.permissions.request({ name: '[2]' });
if (readPerm.state === '[3]' && writePerm.state === 'granted') {
console.log('Permissions granted');
}Attempts:
3 left
💡 Hint
Common Mistakes
Checking for 'denied' instead of 'granted'
Using wrong permission names
Not comparing permission states correctly
✗ Incorrect
You request 'read' and 'write' permissions, and check if the state is 'granted' to confirm access.
