What I want to do
First of all, I would like to state that I am not looking for how to run a function by name (that's explained in this question).
What I want to do is something like this:
function myFunc(){
// some code here
}
myFunc; // this should run the function
// I know it doesn't, but read below
Why I want to do this
There's a Google Easter egg, that if you type in text adventure into the search bar and open the console, you can play a text adventure game.
It asks,
Would you like to play a game? (yes/no)
And if you type in yes
(just the word yes), then it will start the real game. I am trying to figure out how it does that (you didn't type in the ()
after it, and I already learned that you can't see what the user types in the console), but can't figure out what they are doing.
My guess was that they are able to run a function when you type in yes
(maybe a function called yes
?), so that's why I asked this question to understand what they really are doing.
To prevent an XY question: what I really want to do is be able to run some code when the user types something ('yes' maybe) into the console. It's just I think that they are running functions when that happens, so that's why I asked this specific question.
Question
So how is it possible to use the console as an input like Google's text adventure?