Evaluate user input to build logic flow
<p>I'm trying to build a Q&amp;A app in the browser (in JavaScript) to work like an interactive command line app. (Think using <code>printf</code> and <code>scanf</code> in C.) I am making it because I want to help a friend who's learning C, but my background is in JS, and he's working with a lot of cli examples in the terminal which require user input. Here is an example flow for simplicity:</p>

<hr>

<p>It starts with a menu:</p>

<pre><code>Would you like to:
1. Add 16 to a number
2. Multiply each number by 2
3. Find the square root of a number
4. Exit
</code></pre>

<p>User types the number 2 and presses Enter.</p>

<pre><code>&gt; 2
</code></pre>

<p>Since the user selected option 2:</p>

<pre><code>Give me three numbers:
</code></pre>

<p>User presses Enter after typing each number:</p>

<pre><code>&gt; 7
&gt; 4
&gt; 15
</code></pre>

<p>The app responds with:</p>

<pre><code>14
8
30
</code></pre>

<p>And then loops back to the main menu.</p>

<pre><code>Would you like to do:
1: Add 16 to a number
2: Multiply each in a series of numbers by 2
3: Find the square root of two numbers
</code></pre>

<p>etc. …</p>

<hr>

<p>Here's an example of what I have so far if it still doesn't make sense: <a href="https://jsejcksn.github.io/prompt/" rel="nofollow">https://jsejcksn.github.io/prompt</a></p>

<p>I don't need any help parsing numbers or storing the data—I already have functions for printing and storing the questions and input. <strong>I just don't get how I'm supposed to wait for the user response and then control the logic flow of the app since JS can't be paused to wait for the input.</strong></p>

<p>Am I on the right track with <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise" rel="nofollow">promises</a>? I am having the hardest time wrapping my head around promises because I've never used them before, but I think it might be my next step. I just spent 45 minutes looking at all the top search results for documentation and examples, but I still don't get it yet.</p>

<p>Any help appreciated.</p>