WorksheetsJavaScript Unit 1-4 Test
Total questions: 94
Worksheet time: 16hrs 40mins
What is the symbol used for the INCREMENT operator in JS?
+
++
=
==
Repeat something 10 times
repeat 10
for (var i=0; i<10; i++)
repeat { } until 10;
while (i = 10)
Loops in programming start counting from ?
0
1
Any number
Which of these will increase the value of the variable X?
increment (x)
x++;
x=x;
x+1;
Statement lets you ask a question to the program and only run code if the answer is true.
If Else Statement
Condition
If Statement
Parentheses
Control structure that lets us do either one section of code or another depending on a test.
If Else Statement
Condition
If Statement
Parentheses
When we are done with a line what do we put at the end?
a colon :
a semi-colon ;
a period .
a quotation mark "
When we surround a word with quotes "David" it's called ?
a program
a loop
a string
a command
What is a variable
Store values in containers so we can use them later.
Store values in containers so we can use them never.
Store values in containers so we can use them once.
Store values in containers so we can't use them later.
A short form writing the word variable is
rav
VAR
var
varia
How many times will the following code print "Welcome to Java"?
var count = 0;
while (count < 10) {
println("Welcome to Java");
count++;
}
8
9
10
0
A store has 20 apples in its inventory. How can you store this information in a JavaScript variable?
var numApples == 20;
20 = numApples;
var numApples = 20;
var num apples = 20;
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?
var applesToBuy = readLine("How many apples would you like? ");
var applesToBuy = println("How many apples would you like? ");
var applesToBuy = readInt("How many apples would you like? ");
var applesToBuy = nextInt("How many apples would you like? ");
You are splitting up all of your apples equally between 3 people. Which statement below will calculate how many apples will be left over?
var leftOver = numApples / 3;
var leftOver = 3 / numApples;
var leftOver = numApples % 3;
var leftOver = 3 % numApples;
In a graphics canvas, what are the coordinates of the bottom right corner of the window?
0, 0
0, getWidth()
getHeight(), getWidth()
getWidth(), getHeight()
What are the coordinates of the center of the window?
getWidth(), getHeight()
getWidth() / 2, getHeight() / 2
getHeight() - getWidth(), getWidth() - getHeight()
getHeight() / 2, getWidth() / 2
In the following code:
What is the meaning of the x variable?
The x coordinate of the center of the circle
The x coordinate of the left edge of the circle
The radius of the circle
The position of the circle
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?
We never set the circle’s radius. We need to add the line
circle.setRadius(40);
After line 4
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);
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);
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
What is the output of the following program: (Assume the user enters ‘Florence’ then ‘Fernandez’.)
Fernandez Florence
Florence
Fernandez
FlorenceFernandez
Florence Fernandez
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?
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? “);
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? “);
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? “);
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? “);
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)
println(distance/(time/60));
println(distance/time);
println(distance*(time*60));
println(distance*time);
What is printed to the screen when the following program is run?
1
2
3
4
What is printed to the screen if the user enters ‘5’ when the following program is run?
5
25
30
50
What does the following program do?
Draws a circle to the center of the canvas with size based on user inputted value
Draws a circle on the canvas with the center positioned at the coordinate (0,0)
Draws a circle that is positioned in the bottom right corner of the canvas
Draw a circle on the canvas that is always tangential to the top and left sides of the canvas
If a user enters a diameter value in the variable diameter, how would we use this to draw the correct sized circle?
What data type would be used to store the price of a shirt?
boolean
float
string
integer
What data type is used for: age = 15?
Boolean
String
Integer
Boolean
If I am asking the user to input their name, which would I use?
readInt
readFloat
println
readLine
Is this code correct?
var =readLine("What class are you in? ");
yes
no
Which option below correctly represents how to declare and initialize a variable?
var num = 7;
num = 7;
var num
print(7);
What is the keyword to display(output) to the screen in JavaScript?
printline
printLn
println
What makes the following command an invalid Karel command?
turnleft();
It should end in a colon rather than a semicolon
The l should be a capital L
It should start with a capital T
This command is correct
What is the result of the code below?
function start(){
var dog= !false;
println ("Do I have a dog? " + dog);
}
true
false
What is missing? (fill in the blank)
_____(var i = 0; i < 5; i++){
if
else
for
while
Which data type is used to ask someone their bank balance?
int
float
Boolean
string
Which function prompts a user for yes/no type input?
readInt
readFloat
readBoolean
readLine
The plus (+) symbol means:
subtract
concatenate
divide
subjugate
What is the result:
println("2 + 2 = " + 4);
2 + 2 = 4
error
4 = 4
2 + 2 4
What Java Processing command draws a rectangle?
What Java Processing command removes the outlines from shapes?
What Java Processing command draws a perfect circle?
What command colors a shape? (Java Processing)
What command draws a line? (Java Processing)
The "stroke" command means
color inside shape
color outside shape
color of blocks
border
What does the "fill" command do
put letters in the shape
put pictures in the shape
put color in the shape
put code in the shape
What is the second step of a for loop?
declare variable
check the condition
increment
decrement
Is this code correct?
var name = readLine("What is your name? ");
yes
no
Which is appropriate for a variable name?
numDays
1Day
Day#1
Num Days
Which choice would we use for this program:
Create a program that displays "We need snow days!" 100 times.
for loop
while loop
no loop needed
How many times will this code iterate?
var i = 5;
while (i < 8){
i++;
println(i);
}
0
3
5
8
What surrounds an if/else statement?
Quotations " "
Curly Brackets { }
Parenthesis ( )
Square Brackets [ ]
What surrounds a string or words?
Quotations " "
Curly Brackets { }
Parenthesis ( )
Square Brackets [ ]
What's the data type for the phoneNumber variable?
String
Number
What's the value of the ageCalc variable?
"19.27"
26.2
"25.7"
19.27
What line of Java Processing code creates a yellow outline around the circle?
fill("yellow");
noStroke("yellow");
background ("yellow");
stroke("yellow");
a period
the semi-colon ;
nothing, it looks great!
the rest of the word rectangle
What is the result of 12 % 5 ?
2
17
60
7
What operator can be used with both strings and numbers?
"-"
"/"
"+"
"*"
Which command will set the position of Circle on 100 x position and 75 on y position.
circle.setPosition(75, 75);
circle.setPosition(100, 100);
circle.setPosition(100, 75);
circle.setPosition(75, 100);
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
}
add(circle);
add(circle)
add(Circle);
add(circle):
Which command get the 1/3 0f height of canvas when creating a rectangle:
var rectHeight = Height() / 3;
var rectHeight = getHeight() / 2;
var rectHeight = getHeight() / 3;
var getrectHeight = getHeight() / 3;
What does this line of code do?
Declares AND sets a variable
Declares a variable
Sets a variable
Adds a value to a variable
In the following line of Java Processing code -
rect(200, 150, 50, 120); What does the last number (120) stand for?
X-coordinate
Y-coordinate
Width of rectangle
Height of rectangle
In the following line of Java Processing code -
rect(200, 150, 50, 120); What does the first number (200) stand for?
X-coordinate
Y-coordinate
Width of rectangle
Height of rectangle
In the following line of Java Processing code -
rect(200, 150, 50, 120); What does the 3rd number(50) stand for?
X
Y
W
H
11 % 2
0
1
5
2
10 % 4
1
0
2
3
10 % 9
1
0
2
9
15 % 6
2
3
1
4
17 % 7
5
4
2
3
10 % 3
0
1
2
3
20 % 8
6
0
4
2
Which is of the following not correct rule for writting variables names.
These need to be in the lowercase or camel case
spaces are allowed while naming these.
These could be mix of letters, Numbers, _ or $
you cannot start with a number
which the camel case variable name is correct
var my _code_date = "c"
var myCodeDate = "c"
var MycodeDate = "c"
var MyCodeDate = "c"
4 types of variables are:
Boolean, String, int, double
Boolean , String, Variable, conditions
Boolean , String, Numbers, loops
Boolean , String, ints, while loops
How would you create a variable named: myHouse and give it a value "123 Dove St. Valley, CA, 99999".
var a = 2;
Which of these will cause a to be 3 times larger?
a += 3;
a += 4;
a += 1
a++;
Determine what x would be when assignment operators are used given that ×=6 y=12 z=18
x −= 3
x %= 4
4 and 5
3 and 2
3 and 7
1 and 2
Perform the operation on operands of different data types given that a = 4 , b = happy , c= people, d = 9 , e = memories
Solve: b + c
happy people
people happy
happy memories
happy plus
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)
What is the purpose of IF statement #1?
If there is a ball at the current location, pick it up
If there is no ball at the current location, put one down
If the front is clear, move forward
If there is a ball at the last location, pick it up
What is wrong with this code? Select all that apply:
the function name should be Start()
the move() command is undefined
the go() function is undefined
the go() function is called twice in a row
How many tennis balls will Karel put down in this program?
4
5
6
0
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?
Karel will crash into the wall at Street 1, Avenue 1, Facing South
Street 1, Avenue 1, Facing East
Street 2, Avenue 1, Facing North
Street 1, Avenue 2, Facing West
Karel begins at Street 4, Avenue 4 facing East. What is her ending location and direction after running the code?
Street 4, Avenue 6, Facing North
Street 3, Avenue 5, Facing South
Street 4, Avenue 6, Facing East
Street 3, Avenue 6, Facing West
Karel begins at Street 2, Avenue 3 facing North. What is her ending location and direction after running the code?
Street 4, Avenue 4, Facing East
Street 2, Avenue 4, Facing West
Street 4, Avenue 2, Facing West
Karel crashes into a wall
What is a good Postcondition comment for this function?
Karel is one spot above a tennis ball facing East
Karel is on a spot with a tennis ball facing East
Karel goes around the tennis ball facing East
Karel is on a spot with a tennis ball facing North
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 diagonal line of 5 tennis balls going North-East
A straight horizontal line of 5 tennis balls
A straight vertical line of 5 tennis balls
A diagonal line of 5 tennis balls going South-East
What condition should be checked in a While loop to get Karel to pick up all the tennis balls at the current location?
ballsPresent()
noBallsPresent()
frontIsClear()
leftIsBlocked()
What condition should be checked before Karel moves forward to see if there is a wall (hurdle) in front of her?
frontIsClear()
frontIsBlocked()
facingEast()
facingNorth()
