Keyboard input/Obtain a Y or N response: Difference between revisions

Added JavaScript.
(added Scala)
(Added JavaScript.)
Line 446:
return ch == 'y' or 'Y';
]; -).</lang>
 
=={{header|JavaScript}}==
 
Here's how you can asynchronously read a single character in Node.js, using the <code>keypress</code> package.
 
<lang javascript>var keypress = require('keypress');
 
keypress(process.stdin);
 
process.stdin.on('keypress', function (ch, key) {
if (key && (key.name === 'y' || key.name === 'n')) {
var reply = key.name === 'y';
console.log('Reply:', reply);
// ...do something with 'reply'...
}
});
 
process.stdin.setRawMode(true);
process.stdin.resume();</lang>
 
This does not seem to be possible to do synchronously in Node.js or at all in the SpiderMonkey shell.
 
=={{header|Liberty BASIC}}==
Line 475 ⟶ 496:
end sub
</lang>
 
=={{header|Logo}}==
<lang logo>to yorn
845

edits