Exercise

It’s important you have a solid understanding of how functions work, so let’s put your skills of observation to the test and get you writing your own function. Once again, we are going to carry out this exercise inside the Google Chrome JavaScript console.

  1. Open up the developer console.
  2. Define a function that takes in at least two parameters (hold shift while pressing enter to ensure you are able to write the function over multiple lines without executing the function before you have finished declaring it).
  3. Have the function return a value using any of the operators covered in the previous section.
  4. Now call the function with any values you choose.
  5. Ensure you get the expected response before moving on to the next section.

Outputting information

One of the main functions of JavaScript is to present information to your users in ways that are not possible with pure CSS and HTML. Here are some of the ways that JavaScript can output information:

Let’s look into these four different ways of presenting information in JavaScript in more detail.

Outputting to an element

Let’s look again at our earlier example which introduced us to JavaScript and illustrated this technique of outputting text using the inner HTML method.