const readline = require('readline'); const rl = readline.createInterface({ input: process.stdin, output: process.stdout }); rl.question('What is your name? ', (name) => { console.log(`Hello, ${name}!`); rl.question('How old are you? ', (age) => { if (age < 18) { console.log(`Sorry ${name}, you are not old enough to vote yet.`); } else { console.log(`Great ${name}, you are old enough to vote!`); } rl.question('What is your favorite color? ', (color) => { console.log(`Wow, ${color} is a beautiful color!`); rl.question('What is your favorite food? ', (food) => { console.log(`Yum, I love ${food} too!`); rl.close(); }); }); }); });
Preview:
downloadDownload PNG
downloadDownload JPEG
downloadDownload SVG
Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!
Click to optimize width for Twitter