chapter 2 code examples