JavaScript Simplified / Chapter 10 Exercises

  • Index of exercises
  • Email me

1

2

3

4

5

6

7

8

9

10

Congratulations. You've aced all the exercises for this chapter.


To practice on your own, or to check code you believe shouldn't have been scored as incorrect, go to CodePen.


Are you ready to rate JavaScript Simplified? on Amazon?


Rate it on Amazon.

0,1,2,3,4,5,6,7,8,9

0

0

0

0

What is the keyword that displays a box requesting user input? prompt prompt
In the following code, what is the variable that's optional? let gender = prompt(askGender, bestGuess); bestGuess bestGuess
Code a prompt that says "Enter first name". The user's response is assigned to firstName, which hasn't been declared beforehand. let firstName = prompt("Enter first name"); letfirstName=prompt\(•Enterfirstname•\);
Code a prompt that asks "Favorite food?" Include a default response, "pizza". The user's response is assigned to favFood, which hasn't been declared beforehand. let favFood = prompt("Favorite food?", "pizza"); letfavFood=prompt\(•Favoritefood\?•,•pizza•\);
Code a prompt. Assign the user's response to a variable that hasn't been declared beforehand. Make up everything. let nationality = prompt("Enter nationality"); let[a-z_$][a-zA-Z0-9_$]*=prompt\(•.*•\);
Code a prompt. Include a default response. Assign the user's response to a variable that hasn't been declared beforehand. Make up everything. let name = prompt("Enter parrot name", "Polly"); let[a-z_$][a-zA-Z0-9_$]*=prompt\(•.*•,•.*•\);
Code a prompt using a variable rather than a string to specify the information you're asking the user to enter. Assign the user's response to a variable that hasn't been declared beforehand. Make up everything. let response = prompt(question); let[a-z_$][a-zA-Z0-9_$]*=prompt\([a-z_$][a-zA-Z0-9_$]*\);
Assign strings to two variables. Code a prompt specifying the first variable as the question and the second variable as the default answer. Assign the user's response to a third variable. None of the variables have been declared beforehand. Make up everything. let question = "Name of parrot?";
let defaultAnswer = "Polly";
let pName = prompt(question, defaultAnswer);
let([a-z_$][a-zA-Z0-9_$]*)=•.*•;[\r\n]let([a-z_$][a-zA-Z0-9_$]*)=•.*•;[\r\n]let[a-z_$][a-zA-Z0-9_$]*=prompt\(\1,\2\);
  1. Display a prompt, assigning the response to a variable that hasn't been declared previously.
  2. Display the response in an alert.
  3. Click the Result button (or, after revising, don't click, just wait).
  4. Wait a moment.
  5. If you've coded correctly, your prompt will display.
  6. Enter a response in the prompt field and click OK.
  7. If you've coded correctly, an alert will display your response.
  8. For help with this code, see Chapter 10 in the book.
  1. Display a prompt that includes a default response, assigning the response to a variable that hasn't been declared previously.
  2. Code an alert that displays your response.
  3. Click the Result button (or, after revising, don't click, just wait).
  4. Wait a moment.
  5. If you've coded correctly, your prompt will display and the default response will show up in the prompt field.
  6. Accept the default response or enter a different response in the prompt field. Click OK.
  7. If you've coded correctly, an alert will display your response.
  8. For help with this code, see Chapter 10 in the book.