Wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

JavaScript

Total questions: 30

Worksheet time: 16mins

Name
Class
Date
1.
In the following program, when will the function draw be called?
a)
Once, inside of start
b)
Never
c)
Every 20 milliseconds
d)
Every 20 seconds
2.
Which statement will call a function animate every 50 milliseconds?
a)
setTimer(animate, 50);
b)
setTimer(animate(), 50);
c)
for(var i = 0; i < 50; i++){
animate();
}
d)
timer.animate(50);
3.
To add a rectangle named rect to the screen, which command do you need to give?
a)
add(rect);
b)
new(rect);
c)
put(rect);
d)
rect();
4.
What function do you need to call to get the height of the screen?
a)
getScreenHeight();
b)
height();
c)
getHeight();
d)
screenHeight();
5.
What symbol is used to negate a boolean in JavaScript?
a)
NOT
b)
!
c)
~
d)
&
6.
After the following code runs, what is the value of b?
var a = true; 
var b = a || false;
a)
true
b)
false
c)
"b"
d)
"a || false"
7.
After the following code runs, what is the value of isBoth?
var isHuman = true; 
var isRobot = !isHuman; 
var isBoth = isHuman && isRobot;
a)
true
b)
false
c)
"isBoth"
d)
"isHuman && isRobot"
8.
A store has 20 apples in inventory.How can you store this information in a JavaScript variable?
a)
var numApples == 20;
b)
20 = numApples;
c)
var numApples = 20;
d)
var num apples = 20;
9.
We want to print “CodeHS is the best” exactly 25 times.What control structure should we use?
a)
break statement
b)
for loop
c)
while loop
d)
if statement
10.
We want to flip a coin until we get 3 heads in a row.What kind of loop should we use?
a)
for loop
b)
while loop
c)
loop and a half
d)
infinite loop
11.
Why do we write functions?
a)
Make our code easier to understand 
b)
Avoid writing repeated code
c)
Make our code reusable
d)
All of these
12.
What statement can we use inside of a loop to end it?
a)
println
b)
break
c)
stop
d)
else
13.
What kind of statement allows us to run a block code only if a certain condition is true?
a)
if statement
b)
break statement
c)
else statement
d)
for loop
14.
What function do you need to call to ask the user of the program to enter text?
a)
readLine
b)
readln
c)
readInt
d)
println
15.
How can we check if a variable num is even?
a)
num.isEven() will be true
b)
(num % 2 == 0) will be true
c)
(num % 2 == 0) will be false
d)
(num / 2 == 0) will be true
16.
To ask the user of the program for a number, which function should you use?
a)
readLine
b)
readInt
c)
Both readInt and readFloat are for numbers.
d)
readFloat
17.
Which statement allows us to return values from functions?
a)
break
b)
return
c)
if
d)
println
18.
Which of the following returns a random number between 1 and 10?
a)
randomInt(1, 10)
b)
randInt(1, 10)
c)
Randomizer.int(1, 10)
d)
Randomizer.nextInt(1, 10)
19.
How many possible values can Randomizer.nextBoolean() return?
a)
0
b)
1
c)
2
d)
3
20.
Which statement will call a function animate every 50 milliseconds?
a)
setTimer(animate, 50);
b)
setTimer(animate(), 50);
c)
for(var i = 0; i < 50; i++){ animate();}
d)
timer.animate(50);
21.
Why do we want our code to be “reusable”?
a)
To save time
b)
To avoid solving the same problem over and over again
c)
To avoid writing similar code multiple times
d)
All of these
22.
Which statement should we use to determine if ball is hitting the left edge of the window?
a)
if(ball.getX() - ball.getRadius() < 0)
b)
if(ball.getY() > getHeight())
c)
if(ball.getX() - ball.getRadius() > getWidth())
d)
if(ball.getY() < 0)
23.
What is the proper format for a single line comment in CodeHS?
a)
This is a comment
b)
// This is a comment
c)
/* This is a comment
d)
<comment>This is a comment</comment>
24.
How can we teach Karel new commands?
a)
For loop
b)
While loop
c)
Define a new function
d)
Call a function
25.
Which of the following are good examples of things to store as arrays or lists? 
I – A to-do list 
II – A grocery list 
III – A ball in a game of breakout 
IV – A list of balls in a game of breakout 
V – A loop counter variable
a)
II only
b)
III and V
c)
I, II, and IV
d)
I, II, III, IV, and V
26.
It is possible to have an array with 0 items.
a)
true
b)
false
27.
What is an object / map?
a)
An unordered collection of unique items.
b)
An ordered collection of items
c)
A collection of (key, value) pairs
d)
A collection of items stored at (row, column) locations
28.
What is a set?
a)
An unordered collection of unique items
b)
An ordered collection of items
c)
A collection of (key, value) pairs
d)
A collection of items stored at (row, column) locations
29.
What is a grid?
a)
An unordered collection of unique items
b)
An ordered collection of items
c)
A collection of (key, value) pairs
d)
A collection of items stored at (row, column) locations
30.
Which of the following statements will call the function paint every time the mouse is moved?
a)
mouseMoveMethod(paint, e);
b)
mouseMoveMethod(paint);
c)
mouseMoveMethod(paint());
d)
mouseMoveMethod(paint(e))