javascript solution for first exercise