wayground logo

Free Printable Worksheets

NEW

Font size

S
M
L
XL
Worksheets

JavaScript onEvent() Command Quiz

Total questions: 20

Worksheet time: 10mins

Name
Class
Date
1.

What does the `onEvent()` command do in JavaScript?

a)

Adds two numbers

b)

Waits for a specific action to happen

c)

Creates a new variable

d)

Changes the color of the screen

2.

Which of these is a correct way to use `onEvent()`?

a)

`onClick(button1, "click", function() {})`

b)

`whenEvent(button1)`

c)

`onEvent("button1", "click", function() {})`

d)

`clickEvent(button1)`

3.

What type of value is the first part inside the parentheses of `onEvent()`?

a)

A number

b)

An ID name

c)

A variable

d)

A color

4.

What happens when `onEvent("button1", "click", function() {})` is used?

a)

The button disappears

b)

It waits for the user to click the button

c)

The code runs immediately

d)

The button changes size

5.

Where should you place code that you want to run when a user clicks a button?

a)

Inside the `onEvent()` function

b)

Outside the `onEvent()` function

c)

In the HTML file

d)

In a separate JavaScript file

6.

Where should the `setProperty()` function be placed?

a)

Inside the `setProperty()` function

b)

Inside the function block of `onEvent()`

c)

Outside all functions

d)

At the top of the screen

7.

Which of the following is an example of an event type?

a)

"button"

b)

"screen"

c)

"click"

d)

"setProperty"

8.

Which of these events would trigger when a user types in a text box?

a)

"click"

b)

"change"

c)

"input"

d)

"submit"

9.

Which keyword creates a function that runs when an event happens?

a)

`var`

b)

`event`

c)

`onEvent`

d)

`clickFunction`

10.

What should go between the curly braces `{}` in `onEvent()`?

a)

Text only

b)

Another `onEvent()`

c)

Commands to run after the event

d)

A screen ID

11.

What happens if you don’t use `onEvent()`?

a)

The button still works

b)

The app crashes

c)

Nothing will happen when the user clicks the button

d)

The color of the button changes automatically

12.

What does `setProperty()` do in JavaScript?

a)

Stores information

b)

Waits for user input

c)

Changes something about a screen element

d)

Deletes a screen element

13.

Which of these is a correct use of `setProperty()`?

a)

`setProperty("label1", "text", "Hello!")`

b)

`property.set("label1", "text", "Hello!")`

c)

`setProp(label1, Hello!)`

d)

`changeProperty("label1", "text", "Hello!")`

14.

What would this code do? `setProperty("button1", "background-color", "blue")`

a)

Make the text of the button say "blue"

b)

Set a new button

c)

Change the background color of the button to blue

d)

Delete the button

15.

What part of `setProperty()` tells the computer what to change?

a)

The second item (like "text", "image", "color")

b)

The ID

c)

The number

d)

The variable

16.

Which line of code changes the text on a label to say "Welcome"?

a)

`setProperty("label1", "text", "Welcome")`

b)

`setProperty("label1", "color", "Welcome")`

c)

`label1.text = "Welcome"`

d)

`changeText("label1", "Welcome")`

17.

What does `setProperty("image1", "image", "dog.jpg")` do?

a)

Deletes the image

b)

Changes the image to dog.jpg

c)

Writes "dog.jpg" on the screen

d)

Creates a new screen

18.

What property would you change to make text bigger?

a)

"text"

b)

"font-size"

c)

"background-color"

d)

"image"

19.

What would happen if you wrote this code? `setProperty("button1", "text", "")`

a)

It would delete the button

b)

It would hide the text on the button

c)

It would crash the app

d)

It would change the button color

20.

What's the difference between `onEvent` and `setProperty`?

a)

'onEvent' creates elements, 'setProperty' deletes them

b)

'onEvent' listens for actions, 'setProperty' changes element appearance

c)

'onEvent' sets properties, 'setProperty' listens

d)

No difference