Skip to main content
Version: v1.1

✏️ 1.2.1.11 Practice: Interactivity with Window Methods

Goal: In the "Interactivity with Window Methods" lesson, we learned:

  • window methods perform actions in the browser.
  • Examples of window methods include window.alert(), window.prompt(), and window.confirm().
  • JavaScript methods can be chained onto window methods.

Methods are an important part of programming, and you'll be using them constantly. Get the hang of calling window methods by completing the practice exercises listed below.

Warm Up


  • How can we comment out code?
  • What happens when we run code that is commented out?
  • What are the differences between the window.alert(), window.confirm(), and window.prompt() methods?
  • What is data type coercion?

Code


window Methods Practice

Practice using these window methods:

  • Use window.alert() to pop up a dialog box with a warning for the user.
  • Use window.confirm() to ask a yes or no question.
  • Use window.prompt() to ask a question.
  • Save the response to the window.prompt() as a variable. All responses entered by a user into a prompt input are saved as strings (even if the user enters 10, the value is saved as the string, "10"). Run at least 3 string methods of your choice on the string variable that you create from the prompt.
  • Ask the user to enter their age in a prompt, and turn the response into a number using parseInt(). First, save the response as a new variable and turn it into a number. Then, try turning the response into a number without saving it into a variable.