Need help with countown function

Can someone please tell me what I did wrong and point me in the right direction? It should countdown from 5, 4, 3, 2, 1, Kaboom!

Thanks in advance.

import { serve } from "";

let count = 6;
let message = "Start over.";
const handleRequest = (request) => {
  const url = new URL(request.url);

  if (url.pathname === "/count") {
    return new Response(count);
  } else if (count <= 0) {
    return new Response("Kaboom!")
  return new Response(message);

serve(handleRequest, { port: 7777 });

Please post your code instead of a picture - thanks.

Sorry, should be up now.

Thanks. What’s the current behavior you’re seeing? Is there a live demo of this up somewhere?

Note: I’m not an expert in this, but the basic logic seems ok, so its probably some smaller detail?

Here is the link

It’s giving me this error.

Ohhhh, I see it


this behavior is always taken if the pathname is /count

so this part will never occur if the pathname is /count

Gotcha!! I see what you mean. I’m gonna work on it a bit more now that I know where the problem is. I’ll update when I solve it! Thank you!

1 Like

Cool! Let us know if you have more questions!

1 Like

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.