Reading user input with prompt()
Shows a message box, waits for the user to type, then returns what they typed as a string. Store it in a variable. Cancel returns null.
Understanding Reading user input with prompt() in ACARA Digital Technologies Years 7–8
What it does: Pressing Cancel makes prompt() return null, so comparing the stored answer to null detects a cancel. Number() wraps the prompt() result and turns the typed text into a number that can be used in arithmetic. Input from prompt() is always a string, even when the user types digits. prompt() pauses the program with a box, while console.log() just prints to the console. Cancel gives back null. Clicking OK with nothing typed gives an empty string "" instead. The + operator joins strings, so "5" + "3" becomes "53". Use Number() to convert first. You must call prompt with brackets and a message. Without them you only refer to the function and never ask anything.
Common mistakes: The function name is misspelled. It must be prompt, with the letter p before t, otherwise JavaScript throws a ReferenceError. The variable is called next, but this line uses nex, which was never declared. It should be next.
Free printable worksheet with full answer key — or add this module to a class and your students practise it interactively.
This module's key terms are also in a printable crossword (Modules 562–580) and word search (Modules 522–580).
Take this worksheet further — free with Cloodit
Each concept is reinforced from every angle — learned, then applied, then tested.
Cloodit turns curriculum-aligned coding content into journeys students work through one biome at a time.
Over 100 of them, across seven natural biomes.
Turns their work into revision material ready for Flash Cards and Exam study.
Live, competitive practice for the start of the lesson or a teacher-led lesson finisher.
Honour your top performers, or encourage a student who's trying hard — ready to print in seconds.
Quick Questions
Match the Pairs
Key Term
prompt("question")Fill in the Blanks
Spot the Error
Student with a class code? Join your class →