updated javascript to run function every second