Recall & Review
beginner
What does the
prompt() function do in JavaScript?It shows a dialog box that asks the user to enter some text. The text entered is returned as a string.
Click to reveal answer
beginner
How do you store the user's input from
prompt() in a variable?You assign the result of <code>prompt()</code> to a variable, like <code>let name = prompt('Enter your name');</code>.Click to reveal answer
beginner
What type of data does
prompt() return?It always returns a string, even if the user types numbers.
Click to reveal answer
intermediate
How can you convert the string input from
prompt() to a number?Use functions like
Number(), parseInt(), or parseFloat() to convert the string to a number.Click to reveal answer
intermediate
What happens if the user clicks 'Cancel' in a
prompt() dialog?The
prompt() returns null, which means no input was given.Click to reveal answer
What does
prompt('Enter age:') return if the user types 25?✗ Incorrect
prompt() always returns a string, so typing 25 returns '25'.How do you save user input from a prompt into a variable called
userName?✗ Incorrect
You assign the result of
prompt() to the variable like userName = prompt(...).What value does
prompt() return if the user clicks 'Cancel'?✗ Incorrect
Clicking 'Cancel' returns
null to indicate no input.Which function converts a prompt's string input to a number?
✗ Incorrect
parseInt() converts strings to integers.If you want to ask the user for their favorite color, which code is correct?
✗ Incorrect
Use
prompt() and assign it to a variable to get user input.Explain how the
prompt() function works and how to use it to get user input.Think about how you ask a friend a question and get their answer.
You got /4 concepts.
Describe what happens when a user clicks 'Cancel' in a prompt dialog and how to handle it.
Cancel means the user decided not to answer.
You got /3 concepts.