Wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

Chapter 6 : JavaScript Functions & Input/ Output

Total questions: 12

Worksheet time: 7mins

Name
Class
Date
1.

Which of these are correct methods to create a function?

a)

function myFunction {

// Some code }

b)

function myFunction[] {

// Some code }

c)

function myFunction() {

// Some code }

d)

function myFunction(x, y, z) {

// Some code }

2.

Given the following code, which is considered the parameters of the function


function myFunction(a, b, c) {

var x = a + b + c;

}

a)

x

b)

a

c)

b

d)

c

3.

Given the following code, what is the final value of x?


var x = 0;

function myXFunction() {

x = x + 10;

}

x = x + 1;

a)

11

b)

0

c)

10

d)

1

4.

What should go into the indicated location make the final value of x = 11?


var x = 0;

function myXFunction() {

x = x + 10;

}

WRITE CODE HERE

x = x + 1;

a)

function myXFunction()

b)

MYXFUNCTION()

c)

myXFunction()

d)

myxfunction()

5.

What will the final value of x be?


var x = 0;

function myXFunction() {

return 10;

}

x = x + 1;

x = myXFunction();

a)

11

b)

0

c)

10

d)

1

6.

Given the following function.


function myFunction () {

//Some Code }


Which of the code below will allow the following button to invoke myFunction?


<input type="button" id="mybutton" value="Click Me"/>

a)

var h = document.getElementById(“mybutton”); h.addEventListener(“click”, myFunction);

b)

var h = document.getElementById(“mybutton”);

h.onclick(myFunction);

c)

document.getElementById(“mybutton”).addEventListener(“click”, myFunction);

d)

document.getElementById(“mybutton”).onclick(myFunction);

7.

Fill in the blanks to allow the following button invoke the myFunction function when clicked


<button id="myButton" value="Click Me" (a)   />


function myFunction() {

//Some Code }

8.

Which of the following code will allow the button to invoke hisFunction?


<button id="myButton" value="Click Me" ________ />


function hisFunction(X, Y) {

//Some Code }

a)

onclick = "hisFunction()"

b)

onclick = "hisFunction"

c)

onclick = "hisFunction(1)"

d)

onclick = "hisFunction(1, 2)"

9.

Which of this dialog boxes allows the user to verify or accept something?

a)

alert()

b)

confirm()

c)

prompt()

10.

What code will result in the above?

a)

alert("Please enter your phone number:")

b)

confirm("Please enter your phone number:")

c)

prompt("Please enter your phone number:")

11.

In which one of these lines of code is A, B and C considered arguments?

a)

function myFunction(A, B, C) { ... }

b)

function myFunction() {

var A; var B; var C; }

c)

myFunction(A, B, C);

d)

var x = function(A, B, C) { ... };

12.

Identify the parameter in the following code:


function First(Second) {

var Third = 0;

}


First(Fourth);

a)

First

b)

Second

c)

Third

d)

Fourth