Prompt command is not working in replit

I am running a code

let activity = prompt("Enter the activity you are doing:")
switch(activity) {
case "Get up":
console.log("It is 6:30AM");
break;
case "Breakfast":
console.log("It is 7:00AM");
break;
case "Drive to work":
console.log("It is 8:00AM");
break;
case "Lunch":
console.log("It is 12:00PM");
break;
case "Drive home":
console.log("It is 5:00PM");
break;
case "Dinner":
console.log("It is 6:30PM");
break;
}

but prompt command is showing an error

You should use the prompt-sync library.

3 Likes

I tried adding the line but it is still showing error.

What kind of error do you have?

/home/runner/switch/index.js:2
let activity = prompt(β€œEnter the activity you are doing:”)
                      

SyntaxError: Invalid or unexpected token
    at internalCompileFunction (node:internal/vm:73:18)
    at wrapSafe (node:internal/modules/cjs/loader:1178:20)
    at Module._compile (node:internal/modules/cjs/loader:1220:27)
    at Module._extensions..js (node:internal/modules/cjs/loader:1310:10)
    at Module.load (node:internal/modules/cjs/loader:1119:32)
    at Module._load (node:internal/modules/cjs/loader:960:12)
    at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:81:12)
    at node:internal/main/run_main_module:23:47

Node.js v18.16.1

Hi @andreaclash28 !
Could you send the link to your repl?
Thanks!

1 Like

https://replit.com/@andreaclash28/switch#index.js

You are using the wrong type of quotation marks. Instead of β€œ, you should use ".

Corrected code:

const prompt = require('prompt-sync')();
let activity = prompt("Enter the activity you are doing");
switch(activity) {
case "Get up":
console.log("It is 6:30AM");
break;
case "Breakfast":
console.log("It is 7:00AM");
break;
case "Drive to work":
console.log("It is 8:00AM");
break;
case "Lunch":
console.log("It is 12:00PM");
break;
case "Drive home":
console.log("It is 5:00PM");
break;
case "Dinner":
console.log("It is 6:30PM");
break;
}

oops! thank you for the correction.

If your problem is solved, you can mark as a solution the post that helped you the most. So it will be easier for other users facing the same problem to solve their problem.

1 Like

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