finished code for question 3