function for assignment 4 completed.