jojy
jojy

Reputation: 11

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.

Upvotes: 1

Views: 1477

Answers (1)

disitific
disitific

Reputation: 37

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.

Upvotes: 3

Related Questions