const inquirer = require("inquirer")
var questions = [
{
type: "number",
name: "name",
message: "Please the number of players",
validate: function (name) {
var valid = Number.isInteger(name)
return valid || `Please enter a valid whole number`
},
},
]
function promptUser() {
inquirer
.prompt(questions)
.then((answers) => {
console.log(`You entered ${answers["name"]}!`)
})
.catch((error) => console.log(`Please enter a number`))
}
promptUser()
Considering the code above, I've noticed in older videos like this that if you include validate and it fails, the input will be cleared. In my case however, I am getting an NaN that's not automatically cleared. Let's say I start the app and input 'abcdefg':
? Please the number of players NaN
>> Please enter a valid whole number
If i type anything, it will just be added onto the end of NaN. Backspace and delete wont remove the NaN, however it will be removed if i press the up arrow button several times until no more previous inputs show up. Am i doing something wrong?