fix code to define a javascript function