Add JavaScript solution problem 31