Writing code to pass test for ex8 method