Introduction to Functions

Recap

Housekeeping


1. Defining and invoking functions

Materials

Demo: Greet function

2. Arguments and parameters

Materials

Breakout Activity

In pairs, create a function that accepts a number as an argument in kilograms (kgs) and converts the number to pounds (lbs).

  1. You can use these starter files as a starting point.
  2. Declare a function called toPounds that accepts a kilos parameter.
  3. Inside the function, multiply kilos by 2.2 to convert to pounds.
  4. Log the new amount to the console with console.log.
  5. If you have time, use the Window.prompt() method to define kilos from user input.

Don't forget the Pair Programming Dos and Don'ts.

3. Dealing with Coercion

One tricky aspect of Javascript is it will sometimes automatically convert one data type (i.e. a Number) to another (a String). This can lead to unexpected results.

Materials


Lab Time

Prep