implemented the solution to the challege problem of unit 2