Bird
Raised Fist0
Denoframework~20 mins

Scheduled tasks (cron) in Deno - Practice Problems & Coding Challenges

Choose your learning style10 modes available
Challenge - 5 Problems
🎖️
Deno Cron Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ component_behavior
intermediate
2:00remaining
What does this Deno cron task output?
Consider this Deno script using the cron module. What will it print to the console after 3 seconds?
Deno
import { Cron } from "https://deno.land/x/croner@6.0.0/mod.ts";

const task = new Cron("*/1 * * * * *", () => {
  console.log("Tick");
});

setTimeout(() => {
  task.stop();
  console.log("Stopped");
}, 3000);
ANo output, then Stopped
BTick printed once, then Stopped
CTick printed 3 times, then Stopped
DTick printed 5 times, then Stopped
Attempts:
2 left
💡 Hint
The cron runs every second until stopped after 3 seconds.
📝 Syntax
intermediate
1:30remaining
Which cron expression runs a task every 5 minutes?
You want to schedule a task in Deno to run every 5 minutes. Which cron expression is correct?
A"*/5 * * * *"
B"0 */5 * * * *"
C"*/5 * * * * *"
D"0 5 * * *"
Attempts:
2 left
💡 Hint
Standard cron has 5 fields: minute, hour, day, month, weekday.
🔧 Debug
advanced
2:00remaining
Why does this Deno cron task never run?
Look at this code snippet. Why does the scheduled task never print "Hello"?
Deno
import { Cron } from "https://deno.land/x/croner@6.0.0/mod.ts";

const task = new Cron("60 * * * * *", () => {
  console.log("Hello");
});
AThe Cron constructor requires a third argument to start
BThe cron expression is invalid because seconds cannot be 60
CThe callback function is missing an async keyword
DThe import URL is incorrect and causes a silent failure
Attempts:
2 left
💡 Hint
Seconds in cron expressions range from 0 to 59.
❓ state_output
advanced
2:00remaining
What is the value of count after this Deno cron script runs?
This script increments count every 2 seconds and stops after 5 seconds. What is the final count value?
Deno
import { Cron } from "https://deno.land/x/croner@6.0.0/mod.ts";

let count = 0;
const task = new Cron("*/2 * * * * *", () => {
  count++;
});

setTimeout(() => {
  task.stop();
  console.log(count);
}, 5000);
A3
B4
C5
D2
Attempts:
2 left
💡 Hint
Count increments every 2 seconds until stopped at 5 seconds.
🧠 Conceptual
expert
2:30remaining
Which statement about Deno's Cron module is true?
Choose the correct statement about how Deno's Cron module schedules tasks.
ACron tasks run in separate threads automatically to avoid blocking the main thread
BCron tasks only support scheduling with minute-level precision, not seconds
CCron tasks require manual invocation of a start() method after creation to run
DCron tasks execute synchronously on the main event loop and can block other operations
Attempts:
2 left
💡 Hint
Consider how JavaScript event loops handle scheduled callbacks.

Practice

(1/5)
1. What is the main purpose of using scheduled tasks (cron) in Deno?
easy
A. To compile Deno scripts faster
B. To manually trigger functions on user input
C. To debug code step-by-step
D. To run code automatically at specific times or intervals

Solution

  1. Step 1: Understand scheduled tasks

    Scheduled tasks run code automatically without manual intervention.
  2. Step 2: Identify cron job purpose in Deno

    Deno's cron jobs automate running code at set times or intervals.
  3. Final Answer:

    To run code automatically at specific times or intervals -> Option D
  4. Quick Check:

    Scheduled tasks = automatic timed code run [OK]
Hint: Scheduled tasks run code on a timer, not manually [OK]
Common Mistakes:
  • Confusing scheduled tasks with manual triggers
  • Thinking cron is for debugging
  • Assuming cron speeds up compilation
2. Which of the following is the correct way to import the croner library in a Deno script?
easy
A. import Cron from "croner";
B. require('croner');
C. import { Cron } from "https://deno.land/x/croner@6.0.0/mod.ts";
D. import * as Cron from 'cron';

Solution

  1. Step 1: Check Deno import style

    Deno uses ES module imports with URLs, not CommonJS require.
  2. Step 2: Identify correct croner import

    The official croner import uses a URL with version and named import.
  3. Final Answer:

    import { Cron } from "https://deno.land/x/croner@6.0.0/mod.ts"; -> Option C
  4. Quick Check:

    Deno imports use URLs and named imports [OK]
Hint: Deno imports use full URLs, not short names or require [OK]
Common Mistakes:
  • Using require() which is Node.js style
  • Importing from 'cron' instead of 'croner'
  • Using wildcard import without URL
3. What will the following Deno croner code output when run?
import { Cron } from "https://deno.land/x/croner@6.0.0/mod.ts";
const cron = new Cron("* * * * *", () => {
  console.log("Hello every minute");
});
cron.start();
medium
A. Prints "Hello every minute" every second
B. Prints "Hello every minute" every minute
C. Prints "Hello every minute" once immediately
D. Throws a syntax error

Solution

  1. Step 1: Understand the cron pattern "* * * * *"

    This pattern means the task runs every minute.
  2. Step 2: Analyze the callback behavior

    The callback logs "Hello every minute" each time the cron triggers.
  3. Final Answer:

    Prints "Hello every minute" every minute -> Option B
  4. Quick Check:

    Cron pattern "* * * * *" = every minute [OK]
Hint: Five stars in cron means every minute [OK]
Common Mistakes:
  • Thinking it runs every second
  • Expecting immediate output without waiting
  • Confusing cron syntax with other formats
4. Identify the error in this Deno croner code snippet:
import { Cron } from "https://deno.land/x/croner@6.0.0/mod.ts";
const cron = new Cron("60 * * * *", () => {
  console.log("This runs every hour");
});
cron.start();
medium
A. The cron pattern "60 * * * *" is invalid because minutes must be 0-59
B. Missing await before cron.start()
C. Callback function should be async
D. Cron library does not support hourly tasks

Solution

  1. Step 1: Check the cron pattern validity

    Minutes field must be between 0 and 59; "60" is invalid.
  2. Step 2: Confirm other code parts

    cron.start() does not require await; callback can be sync; hourly tasks are supported.
  3. Final Answer:

    The cron pattern "60 * * * *" is invalid because minutes must be 0-59 -> Option A
  4. Quick Check:

    Minutes range = 0-59, 60 is invalid [OK]
Hint: Minutes in cron must be 0-59, not 60 or above [OK]
Common Mistakes:
  • Using invalid minute value 60
  • Thinking cron.start() needs await
  • Assuming callback must be async
5. You want to schedule a Deno task to run every weekday at 9:30 AM using croner. Which cron pattern is correct?
hard
A. 30 9 * * 1-5
B. 9 30 * * 1-5
C. 30 9 * * 6,7
D. 0 9 * * 1-5

Solution

  1. Step 1: Understand cron fields order

    Cron fields are: minute, hour, day of month, month, day of week.
  2. Step 2: Match 9:30 AM on weekdays

    Minute = 30, hour = 9, day of week = 1-5 (Monday to Friday).
  3. Final Answer:

    "30 9 * * 1-5" -> Option A
  4. Quick Check:

    Minute=30, Hour=9, Weekdays=1-5 [OK]
Hint: Minute first, hour second, weekdays 1-5 for Mon-Fri [OK]
Common Mistakes:
  • Swapping hour and minute fields
  • Using weekend days 6,7 instead of weekdays
  • Setting minute or hour to zero incorrectly
Recommended

Ready to prove it?

Pass the test and this pattern moves unknown strong while earning +1 Grip toward your certificate.

10 questions~5 mineasy hard