created separate methods for click event and used addEventlistner instead of onclick