Learn Form Validation by Building a Calorie Counter - Step 53

Tell us what’s happening:

In previous Role playing game we used a different way to trigger button click event.it was like :
btn.onclick=abc; here abc was the reference to function abc. But in calorie counter we are using eventListerner to trigger click. How to decide when to use which method?

Your code so far

<!-- file: index.html -->

/* file: styles.css */

/* file: script.js */
// User Editable Region



// User Editable Region

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/134.0.0.0 Safari/537.36

Challenge Information:

Learn Form Validation by Building a Calorie Counter - Step 53

onclick will work only for clicking, the event listener will work for many more types of events. You can always use addEventListener and use the appropriate event type, input, change, click etc

1 Like