I'm teaching programming to a kid using javascript / node.js and we were going to make a number guessing game. But I found that readline
module only supports async, this means that the game logic can't be:
while(true){
guess=input(); // I seem to need block here
ans=checkGuess(guess);
displayAns(ans);
if(ans==0)break;
}
Instead, I see that instead of a simple loop, I will need to call input
in displayAns
which is called by checkGuess
, which is called by input
- and that is definitely a ugly mess. I don't think I should be teaching the kid CPS just to solve this easy problem.
Is there a simple and easy way for a kid to make this game in node.js? Or am I using the wrong language (maybe BASIC instead?)
By the way, in javascripter's answer he said to use node commander
. node commander has no input functions any more );
Use the question
method it pauses the input stream which, for your purpose, would be the same as "synchronous"