wayground logo

Free Printable Worksheets

NEW

Font size

S
M
L
XL
Worksheets

Javascript Part 2

Total questions: 70

Worksheet time: 36mins

Name
Class
Date
1.

Indicates the beginning and the end of a JavaScript section. / Indique le début et la fin d'une section JavaScript.

a)

<html> </html>

b)

<style> </style>

c)

<article> </article>

d)

<script> </script>

2.

How can a developer show a pop-up message to the user on the browser window? / Comment un développeur peut-il afficher un message contextuel à l'utilisateur dans la fenêtre du navigateur?

a)

alert

b)

prompt

c)

console.log

d)

<p> tag

3.

Which message will the user see? / Quel message l'utilisateur verra-t-il?

a)

"Hello user"

b)

No message / Pas de message

c)

"Goodbye user"

d)

"message + user"

4.

Which of the following JavaScript methods are you most likely to use to activate a button? / Laquelle des méthodes JavaScript suivantes êtes-vous le plus susceptible d'utiliser pour activer un bouton?

a)

onmouseover

b)

onload

c)

whenclick

d)

onclick

5.

What DOM Property is used to update the text of an HTML tag? / Quelle propriété DOM est utilisée pour mettre à jour le texte d'une balise HTML?

a)

id

b)

innerHTML

c)

src

d)

style

6.

What is one key characteristic of an id? / Quelle est une caractéristique clé d'un identifiant?

a)

It must be capitalized / Il doit être capitalisé

b)

It must be unique to one tag / Il doit être unique à une balise

c)

It cannot include numbers / Il ne peut pas inclure de chiffres

d)

It must go in the closing tag / Il doit aller dans la balise de fermeture

7.

Which of the following is the proper way to call the testFunction() function when a button is clicked? / Laquelle des propositions suivantes est la bonne façon d'appeler la fonction testFunction () lorsqu'un bouton est cliqué?

a)

onclick=testFunction

b)

when button clicked = "testFunction()"

c)

onclick="testFunction()"

d)

onclick="testFunction"

8.

DOM get element by id is? / DOM get élément par id est?

a)

Document.Getelementbyid()

b)

document.getElementById()

c)

Document.getElementByID()

d)

DOM.getElmentById()

9.
Which built-in method returns the characters in a string beginning at the specified location?
a)
substr()
b)
getSubstring()
c)
slice()
d)
None of the above.
10.
Which of the following function of String object returns the calling string value converted to upper case?
a)
toLocaleUpperCase()
b)
toUpperCase()
c)
toString()
d)
substring()
11.
Which of the following function of Array object adds one or more elements to the end of an array and returns the new length of the array?
a)
pop()
b)
push()
c)
join()
d)
map()
12.
Which of the following function of Array object reverses the order of the elements of an array?
a)
reverse()
b)
push()
c)
reduce()
d)
reduceRight()
13.
Which object is passed as the argument to handlers for keydown, keyup, and keypress events?
a)
KeyboardEvent
b)
Key Event
c)
Mouse Event
d)
Alphabet Event
14.

How are the objects organized in the HTML DOM?

a)

Class-wise

b)

Queue

c)

Hierarchy

d)

Stack

15.

The paragraph P Tag is a part of_______

a)

<body>

b)

<html>

c)

<h1>

d)

both <body> <html>

16.

The node directly above a node is called

a)

sibling

b)

child

c)

parent

d)

ancestral

17.

The primary purpose of the array map() function is that it __________

a)

maps the elements of another array into itself

b)

passes each element of the array and returns the necessary mapped elements

c)

passes each element of the array on which it is invoked to the function you specify, and returns an array containing the values returned by that function

d)

pass the elements of the array into another array

18.

Which syntax is used to describe elements in CSS?

a)

Protectors

b)

Selectors

c)

Both Protectors and Selectors

d)

Protectors or Selectors

19.

Remove an item from the end of an array.

let cats = ['Bob', 'Willy', 'Mini'];


cats.pop();

a)

['Bob','willy','Mini'];

b)

['Bob','willy'];

c)

['willy','Mini'];

d)

['Bob','Mini'];

20.
An array is;
a)
Shapes
b)
Sizes
c)
Options
d)
Lists of data
21.

What is first index value of an array?

a)

-1

b)

0

c)

1

d)

undefine

22.
What surrounds an array?
a)
Quotations
b)
Curly Brackets
c)
Parenthesis
d)
Square Brackets
23.
array = [1,2,3,4,5]
What is the length of this array?
a)
5
b)
4
c)
0
d)
125.4
24.

Which definition below best describe an array?

a)

An array is a function identifier that can hold more than one parameter.

b)

An array is a beam of light.

c)

An array is a special variable, which can hold more than one value at a time.

d)

An array is a special function, which can hold more than one value at a time.

25.

What is proper syntax for declaring a array in JavaScript?

a)

var arrayName =[ ];

b)

var arrayName[ ] ={ };

c)

array arrayName ={ };

d)

obj var arrayName =[ ];

26.

Which of the variables below is an array?

a)

var names="array"

b)

var names = array;

c)

var names = [];

d)

var names[];

27.

What will be the output to the console for the following code:


var colors =["Red", "Green", "Yellow", "Orange", "Blue"];

colors.splice(0,3, "Purple");

console.log(colors);

a)

["Purple", "Green", "Yellow"]

b)

["Purple", "Green", "Yellow", "Orange", "Blue"]

c)

["Red", "Green", "Yellow", "Orange", "Blue"]

d)

["Purple", "Orange", "Blue"]

28.
How would you change the first element in an array?
a)
nums[1] = "New!";
b)
nums = "New!";
c)
var nums[1] = "New!";
d)
nums[0] = "New!";
29.
array = [1,2,3,4,5];
What is the highest position in this array?
HINT: Remember arrays start at position 0!
a)
4
b)
5
c)
0
d)
125.7
30.
What property tells you how many items are in an array?
a)
length
b)
count
c)
items
d)
num
31.
Which is the correct code to remove the 1 from this array?:
arr = [1,2,3,4,5];
a)
arr.append(6);
b)
arr.splice(0, 1);
c)
splice(arr, 6);
d)
append(arr, 6);
32.
array = [1,2,3,4,5]
What would the array look like after we execute this?:
array.splice(0, 1);
a)
[2,3,4,5]
b)
[2,3,4,5,1]
c)
[1,2,3,4]
d)
[5,4,3,2]
33.

The length() method for an array will return _____.

a)

the number of elements in the array

b)

the last index value of the array.

c)

the length of the name of the array variable

d)

the capacity of the array

34.

The push() method adds a new element to the end of an array

a)

true

b)

false

35.
Which of these lines of code show how to validly store an array with 3 items?
a)
var nums = [42, 3, 7];
b)
var nums = 3, 42, 7;
c)
var nums = [3];
d)
var nums = (3, 42, 7);
36.
Which of these for loops would iterate through each item of the nums array (no more, no less)?
a)
for (var i = 0; i < nums; i++) { }
b)
for (var i = 1; i < nums.length; i++) { }
c)
for (var i = 1; i < nums; i++) { }
d)
for (var i = 0; i < nums.length; i++) { }
37.

What is proper syntax for declaring a array in JavaScript?

a)

var arrayName =[ ];

b)

var arrayName[ ] ={ };

c)

array arrayName ={ };

d)

obj var arrayName =[ ];

38.

The push() method append to the _______ of the array.

a)

beginning

b)

middle

c)

end

d)

none of the above

39.

The pop() method removes the _______ element of the array.

a)

beginning

b)

middle

c)

end

d)

none of the above

40.

The push() method adds a new element to the beginning of an array.

a)

true

b)

false

41.

The shift() method removes the first array element and "shifts" all other elements to a lower index.

a)

true

b)

false

42.

The unshift() method adds a new element to an array (at the beginning), and "unshifts" older elements.

a)

true

b)

false

43.

The sort() method sorts in JavaScript will arrange an array alphabetically, but will not sort numbers in ascending or descending order.

a)

true

b)

false

44.

The sort() method sorts in JavaScript will arrange an array alphabetically, and arrange numbers in ascending order.

a)

true

b)

false

45.

What will be the output to the console for the following code?

a)

["New York", "Texas", "New Mexico", "Arizona"]

b)

["New York", "Texas", "New Mexico", "Arizona", "Washington"]

c)

["Texas", "New Mexico", "Arizona", "Washington"]

d)

["Arizona", "New Mexico", "New York", "Texas", "Washington"]

46.

What will be the output to the console for the following code:


var colors =["Red", "Green", "Yellow", "Orange", "Blue"];

colors.splice(0,3, "Purple");

console.log(colors);

a)

["Purple", "Green", "Yellow"]

b)

["Purple", "Green", "Yellow", "Orange", "Blue"]

c)

["Red", "Green", "Yellow", "Orange", "Blue"]

d)

["Purple", "Orange", "Blue"]

47.

What will be the output to the console for the following code:


var colors =["Red","Green","Yellow","Orange","Blue"];

colors.reverse();

console.log(colors);

a)

["Blue", "Green", "Orange", "Red", "Yellow"]

b)

["Blue", "Orange", "Yellow", "Green", "Red"]

c)

["Red", "Green", "Purple", "Yellow", "Orange", "Blue"]

d)

["Red", "Purple", "Green", "Yellow", "Orange", "Blue"]

48.

What will be the output to the console for the following code:


var colors =["Red", "Green", "Yellow", "Orange", "Blue"];

colors.splice(1,0, "Purple");

console.log(colors);

a)

[ "Orange", "Purple", "Green", "Yellow"]

b)

["Green", "Purple", "Yellow", "Orange", "Blue"]

c)

["Red", "Green", "Purple", "Yellow", "Orange", "Blue"]

d)

["Red", "Purple", "Green", "Yellow", "Orange", "Blue"]

49.

What will be the output to the console for the following code:


var colors =["Red","Green","Yellow","Orange"];

colors.shift();

console.log(colors);

a)

["Red","Green","Yellow"]

b)

["Yellow","Orange"]

c)

["Green", "Yellow", "Orange"]

d)

["Red","Green","Yellow","Orange"]

50.

What will be the output to the console for the following code:


var colors =["Red","Green","Yellow","Orange","Blue","Amber"];

colors.sort();

console.log(colors);

a)

["Red","Green","Yellow","Orange","Blue"]

b)

["Amber", "Blue", "Green", "Orange", "Red", "Yellow"]

c)

["Amber", "Blue", "Green", "Orange", "Red"]

d)

["Red","Green","Yellow","Orange","Blue","Amber"]

51.

What will be the output to the console for the following code:


var colors =["Red","Green","Yellow","Orange"];

console.log(colors.length);

a)

5

b)

3

c)

4

d)

2

52.

What will be the output to the console for the following code:


var numbers =[100,125,137,16];

numbers.sort()

console.log(numbers);

a)

[100, 125, 137, 16]

b)

[16,100, 125, 137]

c)

[16,100, 137, 8]

d)

[8,16,100, 137]

53.

What will be the output to the console for the following code:


var numbers =["100","125","137","16"];

numbers.pop()

console.log(numbers);

a)

["100", "137", "16"]

b)

["125","137","16"]

c)

["100","125","137","16"]

d)

["100", "125", "137"]

54.

To display information to the screen and not to the console which command should you use?

a)

console.log()

b)

display.write()

c)

document.write( )

d)

print.screen()

55.
What surrounds a string?
a)

Single or Double Quotations

b)
Curly Brackets
c)
Parenthesis
d)
Square Brackets
56.

This variable is a non numeric data that cannot be mathematically manipulated

a)

boolean

b)

date

c)

time

d)

string

57.

Numeric data that consist of numbers that can be used in arithmetic and relational operators

a)

string

b)

array

c)

integer

d)

boolean

58.

Answerable by true or false

a)

array

b)

date

c)

string

d)

boolean

59.

/* */

a)

comments

b)

arithmetic operators

c)

relational operators

d)

conditional operators

60.

What Javascript code matches this statement:

Their name is Kim and they are less than 16 years old

a)

if (name = "Kim" && age < 16 )

b)

if (name = "Kim" || age < 16 )

c)

if (name === "Kim" && age < 16 )

d)

if (name === "Kim" || age < 16 )

61.

How many choices are possible when using a single if-else statement?

a)

1

b)

2

c)

3

d)

4

62.

What Javascript code matches this statement:

The player's health is 0 and they still have a life remaining.

a)

if (health == "0" && lives > "0")

b)

if (health === 0 && lives >= 0)

c)

if (health <1 && lives > 0)

d)

if (health === 0 && lives > 0)

63.

What Javascript code matches this statement:

The player has gathered at least 300 coins or reached the end of the level.

a)

if ("coins" >= 300 && "end" == true)

b)

if (coins >= 300 || end == true)

c)

if ("coins" >= 300 OR "end" == true)

d)

if ("coins" >= 300 || "end" == true)

64.

What kind of statement is an If statement?

a)

comparison statement

b)

anecdotal statement

c)

conditional statement

d)

looping statement

65.

What kind of operators do If statements use to test conditions?

a)

comparison operators

b)

arithmetic operators

c)

array operators

d)

bitwise operators

66.

What happens when an If statements conditional is not true?

a)

the if statement executes

b)

Nothing happens

c)

the if statement start over

d)

all options are correct

67.

What will be the output of the following JavaScript code?


if (10 > 5) {


var outcome = "if block";


}​


outcome;

a)

10

b)

5

c)

if block

d)

none

68.

What will be the output of the following JavaScript code?


if ("cat" === "dog") {


var outcome = "if block";


} else {


var outcome = "else block";


}


outcome;

a)

if block

b)

else block

c)

both a And b

d)

none

69.

Which of these is not a type of loop in JavaScript?

a)

while

b)

for

c)

do while

d)

repeat

70.

Which of these expressions is NOT a valid way to add 1 to a variable in JavaScript?

a)

x++

b)

x+=1

c)

x=x+1

d)

x+