70-480 Exam QuestionsBrowse all questions from this exam

70-480 Exam - Question 42


You troubleshoot a webpage that contains the following HTML element:

height= "300">Your browser does not support the HTML5 canvas.

The following JavaScript code is included in a script tag in the HEAD section of the webpage: (Line numbers are included for reference only.)

Exam 70-480 Question 42

You need to invoke the clickReporter() JavaScript function when a user clicks the mouse on the canvas HTML element.

What should you do?

Show Answer
Correct Answer: C

To invoke the clickReporter() JavaScript function when a user clicks the mouse on the canvas HTML element, you need to assign the clickReporter function to the onclick event of the canvas element. This can be done by using canvas.onclick = clickReporter;. This way, when the canvas is clicked, the clickReporter function will be executed, displaying the alert message. Adding "clicked" as an attribute in the HTML is not valid syntax, and the other options do not correctly assign the event handler.

Discussion

7 comments
Sign in to comment
Arcarnan
Oct 23, 2019

A is incorrect, as clicked is not valid syntax. The correct answer here should be C.

JoelChuca
Sep 25, 2020

Yes, C is the correct. https://codepen.io/chobe/pen/QWNojKm

AOD01
Jan 22, 2021

Im test the code with response A and it's ok

PhiDang
Feb 29, 2020

The correct answer is C.

Etnic
Nov 14, 2019

both A and C worked for me.

stef1
Mar 30, 2020

A would be correct if it was: onclick= "clickReporter()" . C is correct and working perfectly.

RJGV
Sep 2, 2020

C is correct when I typed it all into repl.it

Lonan
Nov 25, 2019

Isn't it D?

nootje
Sep 28, 2021

The only correct answer is C. For A to work you need onclick instead of clicked