Click 'Run' to go.
Often you will want to pause the program, ask for some information, and receive it. Here we will be asking for and getting a number.
There are a lot of ways to get a value into a variable. We could just assign a value within the code using a statement like:
That is called hard coding the assignment. The variable x would be set to 5 every time the program was run.
However, what if you wanted the user of the program to set the value of a variable differently every time the program was run? Then you would use a process like we are looking at here. You would ask, or prompt, the user for the information and then wait for the user to type in the value.
The flowchart for this demo:
Here's some imaginary computer code for this program:
x = prompt("Enter value:");
Suggested next article:
The following article is related to this demo: