NEW
Font size
WorksheetsJavaScript onEvent() Command Quiz
Total questions: 20
Worksheet time: 10mins
What does the `onEvent()` command do in JavaScript?
Adds two numbers
Waits for a specific action to happen
Creates a new variable
Changes the color of the screen
Which of these is a correct way to use `onEvent()`?
`onClick(button1, "click", function() {})`
`whenEvent(button1)`
`onEvent("button1", "click", function() {})`
`clickEvent(button1)`
What type of value is the first part inside the parentheses of `onEvent()`?
A number
An ID name
A variable
A color
What happens when `onEvent("button1", "click", function() {})` is used?
The button disappears
It waits for the user to click the button
The code runs immediately
The button changes size
Where should you place code that you want to run when a user clicks a button?
Inside the `onEvent()` function
Outside the `onEvent()` function
In the HTML file
In a separate JavaScript file
Where should the `setProperty()` function be placed?
Inside the `setProperty()` function
Inside the function block of `onEvent()`
Outside all functions
At the top of the screen
Which of the following is an example of an event type?
"button"
"screen"
"click"
"setProperty"
Which of these events would trigger when a user types in a text box?
"click"
"change"
"input"
"submit"
Which keyword creates a function that runs when an event happens?
`var`
`event`
`onEvent`
`clickFunction`
What should go between the curly braces `{}` in `onEvent()`?
Text only
Another `onEvent()`
Commands to run after the event
A screen ID
What happens if you don’t use `onEvent()`?
The button still works
The app crashes
Nothing will happen when the user clicks the button
The color of the button changes automatically
What does `setProperty()` do in JavaScript?
Stores information
Waits for user input
Changes something about a screen element
Deletes a screen element
Which of these is a correct use of `setProperty()`?
`setProperty("label1", "text", "Hello!")`
`property.set("label1", "text", "Hello!")`
`setProp(label1, Hello!)`
`changeProperty("label1", "text", "Hello!")`
What would this code do? `setProperty("button1", "background-color", "blue")`
Make the text of the button say "blue"
Set a new button
Change the background color of the button to blue
Delete the button
What part of `setProperty()` tells the computer what to change?
The second item (like "text", "image", "color")
The ID
The number
The variable
Which line of code changes the text on a label to say "Welcome"?
`setProperty("label1", "text", "Welcome")`
`setProperty("label1", "color", "Welcome")`
`label1.text = "Welcome"`
`changeText("label1", "Welcome")`
What does `setProperty("image1", "image", "dog.jpg")` do?
Deletes the image
Changes the image to dog.jpg
Writes "dog.jpg" on the screen
Creates a new screen
What property would you change to make text bigger?
"text"
"font-size"
"background-color"
"image"
What would happen if you wrote this code? `setProperty("button1", "text", "")`
It would delete the button
It would hide the text on the button
It would crash the app
It would change the button color
What's the difference between `onEvent` and `setProperty`?
'onEvent' creates elements, 'setProperty' deletes them
'onEvent' listens for actions, 'setProperty' changes element appearance
'onEvent' sets properties, 'setProperty' listens
No difference
