I am working on creating different meal menus in this restaurant I have created using JavaScript. I was on my first couple lines of added code when I came across this ReferenceError saying that prompt is undefined. If you need to see full context you can reference the original code here https://repl.it/@qwerty_________/Welcome-to-the-Drivethrough and the code I'm working on here https://repl.it/@qwerty_________/DullFreeMisrac. The official error is right here.
ReferenceError: prompt is not defined
at evalmachine.<anonymous>:2:12
at Script.runInContext (vm.js:74:29)
at Object.runInContext (vm.js:182:6)
at evaluate (/run_dir/repl.js:133:14)
at ReadStream.<anonymous> (/run_dir/repl.js:116:5)
at ReadStream.emit (events.js:180:13)
at addChunk (_stream_readable.js:274:12)
at readableAddChunk (_stream_readable.js:261:11)
at ReadStream.Readable.push (_stream_readable.js:218:10)
at fs.read (fs.js:2124:12)
This is on JavaScript. I have already tried changing it to window.prompt rather than just prompt and it said that window was undefined.
var nam = prompt("Hi, Welcome to the Drivethrough!! What is your name?")
var mprice = 4
var bprice = 8
var cprice = 6
var fprice = 2
var oprice = 3
var fmprice = 5
var gprice = 0
var price = 0
var fcmprice = 10
var cmprice = 4
var kkkprice = 9
var dddprice = 10
var mmmprice = 12
var icprice = 6
var resprice = 999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999
var superprice = 1
I was expecting it to bring up the popup box asking me my name and then me select the breakfast menu to test out chocolate milk, but it instead brought up the error code telling me that the prompt was undefined.
Thank you so much for taking a look at my question. :)
Open terminal and run:-
Step 1: npm init
Step 2: npm install prompt-sync
Step 3: Open the js file (name.js) in which you want to use prompt and import the prompt-sync as given below. (on line 1)
eg: const prompt = require("prompt-sync")();
const prompt = require("prompt-sync")();
let a = prompt("enter a number: ")
console.log(a)
prompt() is a method of the Global window object found in browsers. It's not part of the JavaScript language. If you don't run your code in a browser or an environment that supports the Browser Object Model, window won't be there and if window isn't there, neither will prompt() be. Run your code in a browser.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With