Solved question 6 with a method