code for chapter 2