code tested and works for lesson 3 (around 1/2 done)