liveBook · Manning

Prompt

As explained in Get Programming with JavaScript Next: New features of ECMAScript 2015, 2016, and beyond

A browser-hosted dialog API that displays a message and optionally accepts text input from the user.

Prompt displays a message and asks the user to type a selection, making it useful for simple multiple-choice interaction in a browser-hosted game flow. section 14.2

Here it is wrapped in a choose function that prints numbered options, reads the typed number, retries once on invalid input, then throws if no valid choice is made. section 14.2

Multiple-choice question

A question like “Who is the greatest superhero of all time?” pairs prompt with an options array and returns the chosen index.

Choose the Door flow

The game builds door labels from prizes, shows them through prompt, then uses the returned index to open the selected door with the player’s key. section 14.2

How Get Programming with JavaScript Next: New features of ECMAScript 2015, 2016, and beyond covers it

How deep it goes
Defines prompt use through a helper with numbering, input conversion, one retry, and failure on repeated invalid selection.
Examples
Uses a superhero question and the Choose the Door game to demonstrate selection and response handling.
What it assumes
Assumes arrays, indexing, and basic function calls, while teaching the prompt pattern from scratch.
What you can do after
Operate a prompt-based chooser to collect a valid option index and continue the game flow.
How it connects
Ties to choose, options, lock, unlock, and alert for menu input and prize reveal.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Get Programming with JavaScript Next: New features of ECMAScript 2015, 2016, and beyond. The section links point to the parts of the book it draws on.