I have the following task:
To terminate the procedure for adding users, it is enough to press ENTER instead of entering a name.
But when I use when
in my code, the question is not displayed even the first time. Help me, please.
const questions = [
{
type: 'input',
name: 'user',
message: 'Pls, enter the user name or press ENTER to cancel:',
default: 'nnnnn',
validate: answer => {
if (answer === '') {
return 'Pls, enter a valid name';
}
return true;
},
// when(answers) {
// return answers.user === '';
// },
when(answers) {
answers.user === '';
},
},
{
type: 'list',
name: 'gender',
message: 'Pls, choose the gender:',
choices: ['male', 'female'],
default: 'male',
},