wrappe code in function and call it with an event listener