wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

JavaScript Unit 1-4 Test

Total questions: 94

Worksheet time: 16hrs 40mins

Name
Class
Date
1.

What is the symbol used for the INCREMENT operator in JS?

a)

+

b)

++

c)

=

d)

==

2.

Repeat something 10 times

a)

repeat 10

b)

for (var i=0; i<10; i++)

c)

repeat { } until 10;

d)

while (i = 10)

3.

Loops in programming start counting from ?

a)

0

b)

1

c)

Any number

4.

Which of these will increase the value of the variable X?

a)

increment (x)

b)

x++;

c)

x=x;

d)

x+1;

5.
A condition is __________.
a)
any expression that evaluates to True or False
b)
a built-in function that assigns a Boolean value to a variable
c)
a formula that is executed for a result
d)
an operand that indicates both conditions are True or False
6.
When drawing in Javascript, the coordinates for the top left of the screen is:
a)
0,400
b)
0,0
c)
400,0
d)
400,400
7.

Statement lets you ask a question to the program and only run code if the answer is true.

a)

If Else Statement

b)

Condition

c)

If Statement

d)

Parentheses

8.

Control structure that lets us do either one section of code or another depending on a test.

a)

If Else Statement

b)

Condition

c)

If Statement

d)

Parentheses

9.

When we are done with a line what do we put at the end?

a)

a colon :

b)

a semi-colon ;

c)

a period .

d)

a quotation mark "

10.

When we surround a word with quotes "David" it's called ?

a)

a program

b)

a loop

c)

a string

d)

a command

11.

What is a variable

a)

Store values in containers so we can use them later.

b)

Store values in containers so we can use them never.

c)

Store values in containers so we can use them once.

d)

Store values in containers so we can't use them later.

12.

A short form writing the word variable is

a)

rav

b)

VAR

c)

var

d)

varia

13.

How many times will the following code print "Welcome to Java"?

var  count = 0;

while (count < 10) {  

println("Welcome to Java");  

count++;

}

a)

8

b)

9

c)

10

d)

0

14.
Which of the following is the correct way to declare a variable?
a)
variable myName
b)
var myName
c)
MY_NAME
d)
VAR myName
15.

A store has 20 apples in its 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;

16.

You want to read input from the user to know how many apples they would like to buy. Which statement should you use to read in a number from the user?

a)

var applesToBuy = readLine("How many apples would you like? ");

b)

var applesToBuy = println("How many apples would you like? ");

c)

var applesToBuy = readInt("How many apples would you like? ");

d)

var applesToBuy = nextInt("How many apples would you like? ");

17.

You are splitting up all of your apples equally between 3 people. Which statement below will calculate how many apples will be left over?

a)

var leftOver = numApples / 3;

b)

var leftOver = 3 / numApples;

c)

var leftOver = numApples % 3;

d)

var leftOver = 3 % numApples;

18.

In a graphics canvas, what are the coordinates of the bottom right corner of the window?

a)

0, 0

b)

0, getWidth()

c)

getHeight(), getWidth()

d)

getWidth(), getHeight()

19.

What are the coordinates of the center of the window?

a)

getWidth(), getHeight()

b)

getWidth() / 2, getHeight() / 2

c)

getHeight() - getWidth(), getWidth() - getHeight()

d)

getHeight() / 2, getWidth() / 2

20.

In the following code:

What is the meaning of the x variable?

a)

The x coordinate of the center of the circle

b)

The x coordinate of the left edge of the circle

c)

The radius of the circle

d)

The position of the circle

21.

The following program should draw a circle on the screen, but when we run this code, we don’t see the circle. What is missing from our start function?

a)

We never set the circle’s radius. We need to add the line

circle.setRadius(40);

After line 4

b)

We are setting the position of the ball to be off the canvas. We need to change line 3 to be

circle.setPosition(0, 0);

c)

We are creating the circle incorrectly. We need to specify the width and height. We need to change line 2 to be

var circle = new Circle(40, 40);

d)

We create the circle and position it correctly on the screen, but we never add it to the screen. We need to add the line

add(circle); after line 4

22.

What is the output of the following program: (Assume the user enters ‘Florence’ then ‘Fernandez’.)

a)

Fernandez Florence

b)

Florence

Fernandez

c)

FlorenceFernandez

d)

Florence Fernandez

23.

If you wanted to use the following code to draw a circle to the canvas with the radius, and x and y coordinates given by the user, how would you ask for this information?

a)

var x = readLine(“What is the x coordinate? “);

var y = readLine(“What is the y coordinate? “);

var radius = readLine(“What is the radius of the circle? “);

b)

var x = readInt(“What is the x coordinate? “);

var y = readInt(“What is the y coordinate? “);

var radius = readInt(“What is the radius of the circle? “);

c)

var x = readLine(“What is the x coordinate? “);

var y = readLine(“What is the y coordinate? “);

var radius = readInt(“What is the radius of the circle? “);

d)

var x = readInt(“What is the x coordinate? “);

var y = readInt(“What is the y coordinate? “);

var radius = readLine(“What is the radius of the circle? “);

24.

What line of code would print the speed in km/hr if the distance is given in km and the time is given in minutes? (Speed = distance/time)

a)

println(distance/(time/60));

b)

println(distance/time);

c)

println(distance*(time*60));

d)

println(distance*time);

25.

What is printed to the screen when the following program is run?

a)

1

b)

2

c)

3

d)

4

26.

What is printed to the screen if the user enters ‘5’ when the following program is run?

a)

5

b)

25

c)

30

d)

50

27.

What does the following program do?

a)

Draws a circle to the center of the canvas with size based on user inputted value

b)

Draws a circle on the canvas with the center positioned at the coordinate (0,0)

c)

Draws a circle that is positioned in the bottom right corner of the canvas

d)

Draw a circle on the canvas that is always tangential to the top and left sides of the canvas

28.

If a user enters a diameter value in the variable diameter, how would we use this to draw the correct sized circle?

a)
b)
c)
d)
29.

What data type would be used to store the price of a shirt?

a)

boolean

b)

float

c)

string

d)

integer

30.

What data type is used for: age = 15?

a)

Boolean

b)

String

c)

Integer

d)

Boolean

31.

If I am asking the user to input their name, which would I use?

a)

readInt

b)

readFloat

c)

println

d)

readLine

32.

Is this code correct?


var =readLine("What class are you in? ");

a)

yes

b)

no

33.

Which option below correctly represents how to declare and initialize a variable?

a)

var num = 7;

b)

num = 7;

c)

var num

d)

print(7);

34.

What is the keyword to display(output) to the screen in JavaScript?

a)

print

b)

printline

c)

printLn

d)

println

35.

What makes the following command an invalid Karel command?

turnleft();

a)

It should end in a colon rather than a semicolon

b)

The l should be a capital L

c)

It should start with a capital T

d)

This command is correct

36.

What is the result of the code below?

function start(){

var dog= !false;

println ("Do I have a dog? " + dog);


}

a)

true

b)

false

37.

What is missing? (fill in the blank)

_____(var i = 0; i < 5; i++){

a)

if

b)

else

c)

for

d)

while

38.

Which data type is used to ask someone their bank balance?

a)

int

b)

float

c)

Boolean

d)

string

39.

Which function prompts a user for yes/no type input?

a)

readInt

b)

readFloat

c)

readBoolean

d)

readLine

40.

The plus (+) symbol means:

a)

subtract

b)

concatenate

c)

divide

d)

subjugate

41.

What is the result:

println("2 + 2 = " + 4);

a)

2 + 2 = 4

b)

error

c)

4 = 4

d)

2 + 2 4

42.

What Java Processing command draws a rectangle?

a)
rec (10, 20, 100, 200);
b)
rect (10, 20, 100, 200)
c)
rect (10, 20, 100, 200);
d)
ellipse (10, 20, 40, 40)
43.

What Java Processing command removes the outlines from shapes?

a)
noOutline ();
b)
noColor();
c)
noBorder();
d)
noStroke ();
44.

What Java Processing command draws a perfect circle?

a)
ellipse (80, 60, 100, 105);
b)
ellipse(80, 60, 100, 100);
c)
circle (80, 60, 80, 60):
d)
ellipse (80, 60, 105, 100);
45.

What command colors a shape? (Java Processing)

a)
color (43, 255, 0);
b)
bucket (43, 255, 0);
c)
fill (43, 255, 0);
d)
bucket (43, 255, 0);
46.

What command draws a line? (Java Processing)

a)
stroke (200, 220, 275, 220);
b)
line (200, 220, 275, 220);
c)
horizontal (200, 220,  60, 75);
d)
pencil (200, 220, 275, 220);
47.

The "stroke" command means

a)

color inside shape

b)

color outside shape

c)

color of blocks

d)

border

48.

What does the "fill" command do

a)

put letters in the shape

b)

put pictures in the shape

c)

put color in the shape

d)

put code in the shape

49.
In a programming language, __________ are used to store data values.
a)
tags
b)
codes
c)
files
d)
variables
50.

What is the second step of a for loop?

a)

declare variable

b)

check the condition

c)

increment

d)

decrement

51.

Is this code correct?


var name = readLine("What is your name? ");

a)

yes

b)

no

52.

Which is appropriate for a variable name?

a)

numDays

b)

1Day

c)

Day#1

d)

Num Days

53.

Which choice would we use for this program:


Create a program that displays "We need snow days!" 100 times.

a)

for loop

b)

while loop

c)

no loop needed

54.

How many times will this code iterate?


var i = 5;

while (i < 8){

i++;

println(i);

}

a)

0

b)

3

c)

5

d)

8

55.

What surrounds an if/else statement?

a)

Quotations " "

b)

Curly Brackets { }

c)

Parenthesis ( )

d)

Square Brackets [ ]

56.

What surrounds a string or words?

a)

Quotations " "

b)

Curly Brackets { }

c)

Parenthesis ( )

d)

Square Brackets [ ]

57.

What's the data type for the phoneNumber variable?

a)

String

b)

Number

58.

What's the value of the ageCalc variable?

a)

"19.27"

b)

26.2

c)

"25.7"

d)

19.27

59.

What line of Java Processing code creates a yellow outline around the circle?

a)

fill("yellow");

b)

noStroke("yellow");

c)

background ("yellow");

d)

stroke("yellow");

60.

What is missing from the line of Java Processing code?


rect (100, 234, 24, 65)

a)

a period

b)

the semi-colon ;

c)

nothing, it looks great!

d)

the rest of the word rectangle

61.

What is the result of 12 % 512\ \%\ 5  ?

a)

2

b)

17

c)

60

d)

7

62.

What operator can be used with both strings and numbers?

a)

"-"

b)

"/"

c)

"+"

d)

"*"

63.

Which command will set the position of Circle on 100 x position and 75 on y position.

a)

circle.setPosition(75, 75);

b)

circle.setPosition(100, 100);

c)

circle.setPosition(100, 75);

d)

circle.setPosition(75, 100);

64.

Which command will add the circle to the program.

function start(){

var circle = new Circle(); circle.setColor(Color.blue); circle.setPosition(150, 300);

//missing code

}

a)

add(circle);

b)

add(circle)

c)

add(Circle);

d)

add(circle):

65.

Which command get the 1/3 0f height of canvas when creating a rectangle:

a)

var rectHeight = Height() / 3;

b)

var rectHeight = getHeight() / 2;

c)

var rectHeight = getHeight() / 3;

d)

var getrectHeight = getHeight() / 3;

66.

What does this line of code do?

a)

Declares AND sets a variable

b)

Declares a variable

c)

Sets a variable

d)

Adds a value to a variable

67.

In the following line of Java Processing code -

rect(200, 150, 50, 120); What does the last number (120) stand for?

a)

X-coordinate

b)

Y-coordinate

c)

Width of rectangle

d)

Height of rectangle

68.

In the following line of Java Processing code -

rect(200, 150, 50, 120); What does the first number (200) stand for?

a)

X-coordinate

b)

Y-coordinate

c)

Width of rectangle

d)

Height of rectangle

69.

In the following line of Java Processing code -

rect(200, 150, 50, 120); What does the 3rd number(50) stand for?

a)

X

b)

Y

c)

W

d)

H

70.

11 % 2

a)

0

b)

1

c)

5

d)

2

71.

10 % 4

a)

1

b)

0

c)

2

d)

3

72.

10 % 9

a)

1

b)

0

c)

2

d)

9

73.

15 % 6

a)

2

b)

3

c)

1

d)

4

74.

17 % 7

a)

5

b)

4

c)

2

d)

3

75.

10 % 3

a)

0

b)

1

c)

2

d)

3

76.

20 % 8

a)

6

b)

0

c)

4

d)

2

77.

Which is of the following not correct rule for writting variables names.

a)

These need to be in the lowercase or camel case

b)

spaces are allowed while naming these.

c)

These could be mix of letters, Numbers, _ or $

d)

you cannot start with a number

78.

which the camel case variable name is correct

a)

var my _code_date = "c"

b)

var myCodeDate = "c"

c)

var MycodeDate = "c"

d)

var MyCodeDate = "c"

79.

4 types of variables are:

a)

Boolean, String, int, double

b)

Boolean , String, Variable, conditions

c)

Boolean , String, Numbers, loops

d)

Boolean , String, ints, while loops

80.

How would you create a variable named: myHouse and give it a value "123 Dove St. Valley, CA, 99999".

4 lines
81.

var a = 2;

Which of these will cause a to be 3 times larger?

a)

a += 3;

b)

a += 4;

c)

a += 1

d)

a++;

82.

Determine what x would be when assignment operators are used given that  ×=6\times=6   y=12y=12   z=18z=18  
x −= 3

x %= 4

a)

4 and 5

b)

3 and 2

c)

3 and 7

d)

1 and 2

83.

Perform the operation on operands of different data types given that a = 4 , b = happy , c= people, d = 9 , e = memories


Solve: b + c

a)

happy people

b)

people happy

c)

happy memories

d)

happy plus

84.

What will be printed if this code is executed and the user enters 23?

var num=readInt("Enter a number");

if (num % 2 ==0){

println ("Color is red.");

}else{

println("Color is White");

}

(a)  

85.

What is the purpose of IF statement #1?

a)

If there is a ball at the current location, pick it up

b)

If there is no ball at the current location, put one down

c)

If the front is clear, move forward

d)

If there is a ball at the last location, pick it up

86.

What is wrong with this code? Select all that apply:

a)

the function name should be Start()

b)

the move() command is undefined

c)

the go() function is undefined

d)

the go() function is called twice in a row

87.

How many tennis balls will Karel put down in this program?

a)

4

b)

5

c)

6

d)

0

88.

If Karel starts at Street 2, Avenue 1 facing South, where will Karel end up and what direction will she be facing after running this code?

a)

Karel will crash into the wall at Street 1, Avenue 1, Facing South

b)

Street 1, Avenue 1, Facing East

c)

Street 2, Avenue 1, Facing North

d)

Street 1, Avenue 2, Facing West

89.

Karel begins at Street 4, Avenue 4 facing East. What is her ending location and direction after running the code?

a)

Street 4, Avenue 6, Facing North

b)

Street 3, Avenue 5, Facing South

c)

Street 4, Avenue 6, Facing East

d)

Street 3, Avenue 6, Facing West

90.

Karel begins at Street 2, Avenue 3 facing North. What is her ending location and direction after running the code?

a)

Street 4, Avenue 4, Facing East

b)

Street 2, Avenue 4, Facing West

c)

Street 4, Avenue 2, Facing West

d)

Karel crashes into a wall

91.

What is a good Postcondition comment for this function?

a)

Karel is one spot above a tennis ball facing East

b)

Karel is on a spot with a tennis ball facing East

c)

Karel goes around the tennis ball facing East

d)

Karel is on a spot with a tennis ball facing North

92.

If we call the stairStep function and then put a tennis ball down and repeat those actions 5 times, what kind of shape will we make?

a)

A diagonal line of 5 tennis balls going North-East

b)

A straight horizontal line of 5 tennis balls

c)

A straight vertical line of 5 tennis balls

d)

A diagonal line of 5 tennis balls going South-East

93.

What condition should be checked in a While loop to get Karel to pick up all the tennis balls at the current location?

a)

ballsPresent()

b)

noBallsPresent()

c)

frontIsClear()

d)

leftIsBlocked()

94.

What condition should be checked before Karel moves forward to see if there is a wall (hurdle) in front of her?

a)

frontIsClear()

b)

frontIsBlocked()

c)

facingEast()

d)

facingNorth()