in-class exercise solution

This is my solution
What do you think?