ExamGecko
Question list
Search
Search

List of questions

Search

Related questions











Question 13 - Certified JavaScript Developer I discussion

Report
Export

A developer is creating a simple webpage with a button. When a user clicks this button for the first time, a message is displayed.

The developer wrote the JavaScript code below, but something is missing. The message gets displayed every time a user clicks the button, instead of just the first time.

01 function listen(event) {

02 alert ( 'Hey! I am John Doe') ;

03 button.addEventListener ('click', listen);

Which two code lines make this code work as required?

Choose 2 answers

A.
On line 02, use event.first to test if it is the first execution.
Answers
A.
On line 02, use event.first to test if it is the first execution.
B.
On line 04, use event.stopPropagation ( ),
Answers
B.
On line 04, use event.stopPropagation ( ),
C.
On line 04, use button.removeEventListener(' click" , listen);
Answers
C.
On line 04, use button.removeEventListener(' click" , listen);
D.
On line 06, add an option called once to button.addEventListener().
Answers
D.
On line 06, add an option called once to button.addEventListener().
Suggested answer: C, D
asked 23/09/2024
hajar mechrany
30 questions
User
Your answer:
0 comments
Sorted by

Leave a comment first