HTML5 Online Test Questions part 4

19. The canvas element has a DOM method called __________.

a. getContext
b. getId
c. getElement
d. None of the above

Answer: a. getContext

Explanation: The canvas element has a DOM method called getContext. The getConext method is used to obtain the rendering context and its drawing functions. This function takes one parameter, the type of context 2d.


20. To draw text on a canvas, which property or method is used?

a. font
b. fillText(text,x,y)
c. strokeText(text,x,y)
d. Both a & b

Answer: c. strokeText(text,x,y)

Explanation: The strokeText(text,x,y) method is used to draw text on a canvas. For example, set font to 40px "Calibre" and write a text, with no fill, on the canvas:

var canvas = document.getElementById("myCanvas");
var ctx = canvas.getContext("2d");
ctx.font = "40px Calibre";
ctx.strokeText("TutorialRide",10,60);

stokeText


21. In handling media events which event is generated when the first frame of the media has finished loading?

a. loadstart
b. loadeddata
c. ended
d. error

Answer: b. loadeddata

Explanation: The loadeddata event is fired when the first frame of the media has finished loading. This event occurs when data for the current frame is loaded, but not enough data to play next frame of the specified audio/video.


22. Which attribute is used in <audio> tag to control audio playback?

a. src
b. controls
c. preload
d. autoplay

Answer: b. controls

Explanation: If the control attribute is present in <audio> tag, it will allow the user to control audio playback, including volume, seeking, and pause/resume playback.


23. The HTML canvas is a

a. Three-dimensional grid
b. One-dimensional grid
c. Two-dimensional grid
d. None of the above

Answer: c. Two-dimensional grid

Explanation: HTML canvas is a Two-dimensional grid. The upper-left corner of the canvas has the coordinates (0,0). For example, fillRect parameters (0,0,160,80) which means that draw a 150x75 rectangle on the canvas from the top left corner (0,0).


24. Server-Sent Events does not allow a web page to get updates from a server.

a. True
b. False

Answer: b. False

Explanation: The above statement is false. Server-Sent Events allow a web page to get updates from a server. It allows a web page to get information from the web server automatically.