Event Objects and Conditional Code

Recap

Housekeeping


1. Conditional code blocks

The if/else statement is used to conditionally run code when an expression (code that returns a value) is true.

Materials

Slides

Demo: Greeter with language support

2. Forms: Event.preventDefault()

Demo: Tip Calculator with <select> menu and Event.preventDefault()

Breakout Activity

In pairs, take the form created in the demo, using if, else if and/or else statements, set the tipRate based on the service level selected in the menu.

  • Note: The value of the select menu is stored in the form.service.value property.

3. Equality and Truthiness

Coercion in untyped languages (such as Javascript) produces a concept known as "Truthiness": some values are more equal than others, based on their value type.

Materials


Lab Time


Prep