Homework: User Input

It is time for you to explore how to accept user input on your own. Web browsers have three default methods that accept user input. These can be sued inside of Chrome's Developer Tools in the Javascript Console. They are:

  • prompt(stringArgument);
  • confirm(stringArgument);
  • alert(stringArgument);

Challenge

  1. In classical programming languages, methods that are not void return methods.
  2. Which of these three built-in browser methods are void?
  3. Which are not?
  4. What is the data type that these return?

Hint: You can assign user input to a variable and then call it later.

Research

When you continuously spam a user with these methods, most evergreen browsers will provide the ability to hide popups from a specific website forever. How would this affect your development?

Take a few moments to research the pitfalls of using these browser methods for user input. Have you found any suggestions or alternatives?

Practice Problems

Let's work on a few problems to get your developer chops up to par! Use your user input skills to solve the following problems:

  • Create a conditional or control flow statement (either switch or if) that detects if a student is of the appropriate age to purchase alcohol. Alert them with either a success or failure message.

  • You're at a large convention and developers everywhere need to be organized into a group. Create three arrays: one for Javascript developers, one for Ruby developers, and one for Python developers. Use a conditional or control flow statement to sort through any array. Sort any developer with the name "Bill" to the Javascript array. Sort any developer with the name "James" into the Python array. Sort any developer with the name "Jim" into the Ruby array. Alert (or console.log) the contents of each array when done.

results matching ""

    No results matching ""