Concept Flow - Basic input concepts (prompt overview)
Start Program
Show prompt to user
User types input
Store input in variable
Use input in program
End Program
The program shows a prompt, waits for user input, saves it, then uses it.
let name = prompt('What is your name?'); console.log('Hello, ' + name + '!');
| Step | Action | Input/Output | Variable State |
|---|---|---|---|
| 1 | Show prompt 'What is your name?' | Prompt displayed | name = undefined |
| 2 | User types input | User types 'Alice' | name = undefined |
| 3 | Store input in variable | Input 'Alice' stored | name = 'Alice' |
| 4 | Output greeting | Console logs 'Hello, Alice!' | name = 'Alice' |
| 5 | Program ends | No further action | name = 'Alice' |
| Variable | Start | After Step 2 | After Step 3 | Final |
|---|---|---|---|---|
| name | undefined | undefined | 'Alice' | 'Alice' |
Basic input in JavaScript uses prompt() to ask the user a question. The input is saved in a variable. You can then use this variable in your program. If the user cancels, prompt returns null. Always check or handle user input carefully.