0
0
Javascriptprogramming~5 mins

Basic input concepts (prompt overview) in Javascript - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
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?
Aundefined
B'25' (a string)
Cnull
D25 (a number)
How do you save user input from a prompt into a variable called userName?
AuserName = prompt('Enter name');
Bprompt('Enter name') = userName;
Clet prompt = userName('Enter name');
Dvar userName = alert('Enter name');
What value does prompt() return if the user clicks 'Cancel'?
Anull
Bundefined
CAn empty string ''
D0
Which function converts a prompt's string input to a number?
Aprompt()
Balert()
CparseInt()
Dconsole.log()
If you want to ask the user for their favorite color, which code is correct?
Aprompt('What is your favorite color?') = color;
Bconsole.log('What is your favorite color?');
Calert('What is your favorite color?');
Dlet color = prompt('What is your favorite color?');
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.