Completed problem 1 in javascript