Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to ask the user for their name using prompt.
Javascript
const name = [1]('What is your name?');
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using alert instead of prompt
Using console.log instead of prompt
✗ Incorrect
The prompt function shows a dialog box asking the user for input.
2fill in blank
mediumComplete the code to convert the input string to a number.
Javascript
const age = Number([1]); Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Passing a variable that is not defined
Passing a string literal instead of prompt
✗ Incorrect
The prompt function returns a string. Wrapping it with Number() converts it to a number.
3fill in blank
hardFix the error in the code to correctly store user input in a variable.
Javascript
let city; city = [1]('Enter your city');
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using alert or confirm instead of prompt
Trying to assign console.log output
✗ Incorrect
Use prompt to get input from the user and assign it to the variable.
4fill in blank
hardFill both blanks to ask for a number and convert it to an integer.
Javascript
const input = [1]('Enter a number'); const number = [2](input);
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using alert instead of prompt
Using Number instead of parseInt when integer is needed
✗ Incorrect
First, use prompt to get input as a string. Then use parseInt to convert it to an integer.
5fill in blank
hardFill all three blanks to get user input, convert to number, and check if it is positive.
Javascript
const input = [1]('Enter a number'); const num = [2](input); const isPositive = num [3] 0;
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using parseInt instead of Number for conversion
Using < instead of > for comparison
✗ Incorrect
Use prompt to get input, Number to convert it, and > to check if positive.