Exercise Monday

Goal: In the Functions video, we learned:

  • Functions perform actions in the browser
  • Examples of JavaScript functions are alert(), prompt(), and confirm()
  • Methods can be chained onto functions

Functions are an incredibly important part of programming, and you'll be using them constantly. Begin to get the hang of calling some common JavaScript functions 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 alert(), confirm(), and prompt() functions in JavaScript?

Code


Functions Practice

Practice using JavaScript functions:

  • Use alert() to pop up a dialog box with a warning for the user.
  • Use confirm() to ask a yes or no question.
  • Use prompt() to ask a question.
  • Save the response to the prompt() as a variable. All responses entered by a user in to a prompt input filed 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 a new question and save the response as a new variable and run 3 different string methods on it.