Solved prob3 in JS