solved problem 19 in javascript