Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

77
Views
Options in inquirer.js javascript inputs

Instead of using a bunch of ifs, is there a way to show different options for different selections rather than having to specify directly for each one like I am doing? I think there is the .when option, but I am not really sure how to use it in this situation.

I am trying to let them select the wallet option and then let them view the wallet that they choose. Also, I can't seem to figure out how to send the user back to the beginning of the menu when they select the <<< quit key, so any input into how to do that would be good.

inquirer
.prompt([
    { type:'list',
    message: "Select an option",
    name: 'walletOptions',
    choices: [
        'Wallet',
        'Normal Transaction',
        'Arbitrage'
    ]}
])
.then(({walletOptions}) => {
    
    if (walletOptions === 'Wallet') {
        //let them view and edit wallet
        inquirer
            .prompt([
                { type:'list',
                message: "Select an account",
                name: 'accountOptions',
                choices: [
                    '1',
                    '2',
                    '3',
                    '<<< Quit'
                ]}
            ])
            .then(({accountOptions}) => {
                if (accountOptions === '1') {
                    //display account info for one
                    var walletOne = wallet[1]
                    console.log(walletOne);
                } else if (accountOptions === '2') {
                    //display account info for two
                    var walletTwo = wallet[2]
                    console.log(walletTwo);
                } else if (accountOptions === '3') {
                    //display account info for three
                    var walletThree = wallet[3]
                    console.log(walletThree);
                } else {
                    return ;
                }
        
            })
    
    } else if (walletOptions === 'Normal Transaction') {
        //continue with mainswap.js
        var normalTx = require("./mainswap");
        mainswap.deploy()
        
    } else {
        //continue with ...
    }
});
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Use "rawlist" instead of "list" in the type attribute as in the Official Example

Also remove the unwanted "}" after the choices list.

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!