updated the javascript to feature a function