added the completed javascript function.