The code you posted for both tasks is incomplete.
Post your attempt to combine them and explain what the problems are.