Javascript solution

Can you move the print out of the function?