complete coding for iteration 3.