created this solution in javascript since some of my students were also working on it in JS