Modified challenge 3 into a function and added a test.