简体   繁体   中英

every keypress for prompt-sync in javascript repeats the prompt

Code:

 var prompt = require("prompt-sync")() function start() { var whatbox = prompt('What box would you like to open?(ALL LOWER CASE)') if (whatbox == "School") { box("School") } else if (whatbox == "Park") { box("Park") } else if (whatbox == "Tech" } { box("Tech") } else { console.log("That is NOT a box! Try again and check your spelling!") } } start()

Error: The prompt keeps on repeating every time I press a key.

 var prompt = require("prompt-sync")() function start() { console.log("What box would you like to open?(ALL LOWER CASE)") var whatbox = prompt("Your input >> ") if (whatbox == "School") { box("School") } else if (whatbox == "Park") { box("Park") } else if (whatbox == "Tech" } { box("Tech") } else { console.log("That is NOT a box! Try again and check your spelling!") } } start()

The prompt-sync has this problem where if your prompt text/qustion is too long it fails when refreshing it. To solve this problem, you can simply console.log question and then ask for input.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM