I have looked for this, but haven't found anything similar. In Javascript, I want to know if there is a way to get user input, from say a text area, in the middle of a loop, such as with the input() function from python. Here is an example:
def thing():
color = input("Pick Red, Yellow or Blue")
finished = False
previous = []
while finished == False:
if previous == []:
guess = "red"
response = input("Is your color red?")
previous.append((guess, response))
elif len(previous) == 1:
response = input("is your color blue?")
if response == "yes":
finished = True
This example is not exactly what I am trying to do but basically, I want a way, for a user to be asked things, and for them to put an answer in a text area(HTML), and push a button, which continues a Javascript while loop with the newly received input, and formulates some other question, and so on, until some condition is reached to stop the loop.
Is this possible? Does something in JS mimic this?
prompt('Pick red, Yellow or Blue')in order to make browser show dialog which will ask something and wait for input. However, if you want to do this in HTML - you will need to use callbacks.promptdoes do this, it can be pretty UX breaking. Consider making your code event-driven and using an<input>