Solved problems 4-7 in JS