Error in code execution


Replit Profile:

showing error in code

Welcome to Ask!

Instead of instantly giving you the code, I’ll explain it step-by-step. :slight_smile:

So the first thing you do is read the error. Is it a SyntaxError? A ReferenceError? (There are a lot of different errors. You can find their names and reasons in Google.)

Then you try to find out why that error is happening. For example, if you’re getting a ReferenceError, that means you’re trying to use something that’s not defined. So this means that prompt() is not defined.

The next thing you need to do is try to solve the error. If prompt() doesn’t exist, you need to find another way to get input from the user. If you can’t find a way, Google is your best friend. I like to look at it like this:

  1. Try to figure it out yourself. If you can’t, move on to number 2.
  2. Google. If you still can’t get it working even after trying multiple solutions, or you need some clarification, you can move on to number 3.
  3. Ask on coding forums, like Replit Ask. If they can’t answer your questions, go back to number 1.

So how do you get input from the user? You can use a package called readline.

  1. Import the readline package.
  2. Create an interface with the readline package.
  3. Use the readline package’s builtin functions to get input from the user.

Hope this helped :slight_smile:

1 Like

It’s not working
Can u explain in simple words ?

Can you explain what’s not working? Sorry for the late reply btw.

1 Like

Actually prompt and alert function is not working in javascript

Try this to make prompt work:


Alert function is not working in js
As it is showing object not found

Isn’t alert for vanilla JS only? not node?


You should be using console.log. As @QwertyQwerty88 suggested, prompt and alert are not actually a part of Node.JS, instead, Replit previously added them automatically but has stopped doing this now and does not intend to bring this back.