finished javascript code.