ReferenceError: prompt is undefined. How would I fix this in JavaScript?
ReferenceError: prompt is undefined. How would I fix this in JavaScript?
我正在使用 JavaScript 创建的这家餐厅中创建不同的餐点菜单。当我遇到这个 ReferenceError 说提示未定义时,我正在添加代码的前几行。如果您需要查看完整上下文,可以在此处参考原始代码 https://repl.it/@qwerty_________/Welcome-to-the-Drivethrough and the code I'm working on here https://repl.it/@qwerty_________/DullFreeMisrac。
官方报错就在这里
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)
这是在 JavaScript 上进行的。我已经尝试将其更改为 window.prompt 而不是提示,它说 window 未定义。
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
我原以为它会弹出一个弹出框询问我的名字然后我 select 早餐菜单来测试巧克力牛奶,但它却弹出错误代码告诉我提示是不明确的。
非常感谢您查看我的问题。 :)
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
不会存在,如果 window
不存在,prompt()
也不会存在。 运行 您在浏览器中的代码。
看来您 运行 此代码在 Node.js 环境中,在提供此环境的站点中。 window
对象未在此环境中定义。您可以尝试在浏览器控制台或 HTML 文件中测试您的脚本。
我正在使用 JavaScript 创建的这家餐厅中创建不同的餐点菜单。当我遇到这个 ReferenceError 说提示未定义时,我正在添加代码的前几行。如果您需要查看完整上下文,可以在此处参考原始代码 https://repl.it/@qwerty_________/Welcome-to-the-Drivethrough and the code I'm working on here https://repl.it/@qwerty_________/DullFreeMisrac。 官方报错就在这里
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)
这是在 JavaScript 上进行的。我已经尝试将其更改为 window.prompt 而不是提示,它说 window 未定义。
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
我原以为它会弹出一个弹出框询问我的名字然后我 select 早餐菜单来测试巧克力牛奶,但它却弹出错误代码告诉我提示是不明确的。
非常感谢您查看我的问题。 :)
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
不会存在,如果 window
不存在,prompt()
也不会存在。 运行 您在浏览器中的代码。
看来您 运行 此代码在 Node.js 环境中,在提供此环境的站点中。 window
对象未在此环境中定义。您可以尝试在浏览器控制台或 HTML 文件中测试您的脚本。