Wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

CS II--June 4th Assignment

Total questions: 63

Worksheet time: 38mins

Name
Class
Date
1.

What is the term for a variable declared inside a method?

a)

method variable

b)

local variable

c)

global variable

d)

private variable

2.

What is scope?

a)

the part of a program where the variable exists

b)

a minty mouthwash

c)

a device used to aim a projectile

d)

a device in a submarine that is used to view the surface

3.

What characters denote a block?

a)

< >

b)

[ ]

c)

{ }

d)

( )

4.

Where does a variable exist?

a)

from when it's declared to the end of the block it's in

b)

from when it's declared to the end of the method it's in

c)

from when it's declared to the end of the class it's in

d)

from when it's declared to the end of the program it's in

5.

What term is used to describe data passed into/out of a program?

a)

Variable

b)

Loop

c)

Constant

d)

Parameter

6.

Which of the following is true about global variables?

a)

Globals should never be used.

b)

Globals should be used as little as possible.

c)

JavaScript will not run code that includes globals.

d)

Globals should be used as much as possible.

7.

Which of the following is true about function parameters?

a)

Function parameters should never be used.

b)

Function parameters are locals not globals.

c)

Function parameters are globals not locals.

d)

Function parameters should be used as little as possible.

8.
Every function definition must have
a)
the word "function"
b)
( )
c)
{     }
d)
all of the above
9.
Given:
  function makePic(x , y) {
        //stuff you don't need to know
  }
Which is a correct function call?
a)
makePic(3);
b)
makePic(10, 20);
c)
makePic();
d)
function makePic(2, 7);
10.

If a variable has "global scope" it can be

a)

used anywhere in the program

b)

only used outside of a function

c)

only used inside of a function

d)

used outside of the program

11.

If a variable has "local scope" it is available for use outside of its function.

a)

TRUE

b)

FALSE

12.

Give the definition of variables?

a)

Entities that appear in the program code as fixed values.

b)

Identifier whose value can change during the course of execution of a program

c)

It have standard, predefined meanings and must be used only for their intended purpose.

13.

Why variables must be declared before use? Choose the suitable answer.

a)

To tells the compiler the type of data to store

b)

To make a program easier to understand

14.

Select the types of variables scope.

a)

Local variables

b)

Global variables

c)

Universal variables

15.

An __________ (_) is used to assign

values to variables.

a)

Subtraction Sign -

b)

Equal Sign =

c)

Addition Sign +

d)

Parenthesis ()

16.

The values that are passed on to the function when it is called.

a)

Function

b)

Identifier

c)

Blocks

d)

Argument

17.

All values in a programming language have a "type" - such as a Number, Boolean, or String - that dictates how the computer will interpret it. For example 7+5 is interpreted differently from "7"+"5"

a)

Data Type

b)

Variable

c)

Expression

d)

If-Statement 

18.

Which of the following correctly defines a function that increases the count by 2 until the number 8 is achieved and then refreshes to 0?

a)
b)
c)
19.

Identify the arguments passed to the function in the following code:

function calculateSum(x, y, z) {

return x + y + z;

}

a)

x and y

b)

calculateSum

c)

x, y and z

d)

None

20.

Identify the variable in the following code:

function Alpha(Beta) {

var Gamma = 1;

}

Alpha(Delta);

a)

Alpha

b)

Gamma

c)

Beta

d)

Delta

21.
What is a condition in Karel programming?
a)
What karel does during the program.
b)
A method that returns a true or false answer. Typically used within a control structure.
c)
The number of times a program loops.
d)
The place in code where the program stops running.
22.
How can we teach Karel new commands?
a)
Define a new method
b)
A for loop
c)
A while loop
d)
The run method
23.
Why does a programmer indent their code?
a)
Helps show the structure of the code.
b)
Easier for other people to understand.
c)
A key part of good programming style!
d)
All of the above
24.

Which of these is a valid Karel command in JavaScript?

a)
MOVE
b)
move();
c)
move()
d)
move;
25.
What is top down design?
a)
Top down design is a way of designing your program by starting with the biggest problem and breaking it down into smaller and smaller pieces that are easier to solve.
b)
Top down design is a way of designing your programs starting with the individual commands first
c)
Top down design is a way that you can create designs on a computer to put on a web page
d)
Top down design is a way to use loops and classes to decompose the problem
26.
If Karel is not on a tennis ball, and all directions around are clear, what will happen when running this code?
a)
Karel will not do anything
b)
Karel will go into an infinite loop
c)
Karel will put down a tennis ball
d)
Karel will turn left once
27.
You've defined a function named calcAge that takes three parameters (day/month/year) and returns a value. How do you call that function and store the resulting value?
a)
var calcAge(24, 6, 1984);
b)
var age = calcAge(24, 6, 1984);
c)
var age = calcAge(24/6/1984);
d)
var age = calcAge = 24, 6, 1984;
28.
What keyword do you need to use if you want your function to return a value?
a)
return
b)
echo
c)
sendback
d)
reply
29.
How many parameters should you pass to the line() function?
a)
1
b)
2
c)
4
d)
6
30.
For the line() function, what numbers should you pass to the third and fourth parameters?
a)
The width and height of the line
b)
The end x position and end y position of the line
c)
The amount to rotate and skew the line
d)
Your 2 favorite numbers in the world
31.
How do I declare a new variable?
a)
var newVariable = 5;
b)
Variable int = new Variable();
c)
var 5 = myVariable;
d)
int var = 5;
32.

Choose the program below that correctly calculates the area of a rectangle (length x width) based off the user input of the measurements.

a)

var length = readLine("Length: ");

var width = readLine("Width: ");

var area = length x width;


println("The area is: " + area);

b)

var length = readInt("Length: ");

var width = readInt("Width: ");

var area = length x width;


println("The area is: " + area);

c)

var length = readLine("Length: ");

var width = readLine("Width: ");

var area = length * width;


println("The area is: " + area);

d)

var length = readInt("Length: ");

var width = readInt("Width: ");

var area = length * width;


println("The area is: " + area);

33.

What is the output of the following code if the user enters “6” and then “15”:

“`javascript

var firstNum = readLine(“Enter a number between 1 and 10: “);

var secondNum = readLine(“Enter a number between 11 and 20: “);

var result = firstNum + secondNum;

println(result);

a)

21

b)

6 + 15

c)

615

d)

The program will result in an error

34.

Which command provides a random number?

a)

Randomizer.nextNumber()

b)

Randomizer.nextInt()

c)

RandNumber

d)

nextNumber.Randomizer()

35.

Names that refer to commands, functions, variables and keyword should be written correctly, variable “A” and “a” are two different variables.

a)

Comments

b)

Case Sensitivity

c)

Data Types

d)

Statements

36.
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
37.

His name is John and he is exactly 20 years old

Which of the following is the best way to write the above statement?

a)

if (name = "John" && age ==20 )

b)

if (name == "John" && age ==20 )

c)

if (name = "John" || age ==20 )

d)

if (name == "John" || age ==20 )

38.
A string is used for storing:
a)
Numbers
b)
Integers
c)
Images
d)
Text
39.
In the following code:
var add = function(num1, num2) {   
return num1 + num2;
};
The function will receive two numbers and: 
a)
Add them
b)
Return them
c)
Add them then return their sum
d)
Find their difference
40.

What symbol represents the or operator in JavaScript?

a)

OR

b)

or

c)

||

d)

|

41.

What is the right way to write the function:

makePancakes (Clue: this pancake will be made by putting 3 balls)

a)

function makePancakes(){

putBall();

putBall();

putBall();

}

b)

function makePancakes()

putBall();

putBall();

putBall();

c)

function makePancakes: {

putBall();

putBall();

putBall();

}

d)

function makePancakes(){

putBall();

}

42.

Karel needs to take the ball that is already present on her initial space then move forward four spaces and place the ball. Then turn Left

a)

takeBall();

move 2 times ();

move 2 times ();

putBall();

turnLeft

b)

takeBall();

move();

move();

move();

move();

putBall();

turnLeft();

c)

takeBall();

move();

move();

putBall();

TurnLeft{};

d)

takeBall();

move();

move():

move():

move();

putBall();

turnLeft():

43.

Determine what result each expression yields if it is True or False. Given that x= 7 and y= 9.


( x >2 && y ! == 9)&&( x>= 6 && y ==9)

a)

True

b)

False

44.

Determine what result each expression yields if it is True or False. Given that x= 5 and y= 3.


( x==2 || y == 3 )||( x<6 && y<9)

a)

True

b)

False

45.

Determine what result each expression yields if it is True or False. Given that x= 8 and y= 16.


( x === 8 || y > 5) && ( x! == 7 && y > "11")

a)

True

b)

False

46.

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

47.

Which of the following statements are true about ball?

I – ball is a local variable

II – the ball variable in draw is different from the ball variable in start

III – ball is a global variable

IV – ball’s scope includes both start and draw

a)

III and IV

b)

I and II

c)

III only

d)

I, II, III, and IV

48.

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) { ... };

49.

Choose the correct code to be inserted at line 4 in order to invoke the function.

function lfc(x){

return (x*x);

}

// line 4

a)

A. thisfun(10)

b)

B. lfc(10)

c)

C. function thisfun(10)

d)

D. None of the above

50.

What will be the value of sum after this code runs?

a)

10

b)

4

c)

1

d)

40

51.

Why do we use constant variables?

a)

To avoid having "magic numbers" in our code

b)

To give values a readable name, so that their purpose is clear

c)

To let us easily change the behavior of our program by only having to change a value in one place

d)

All of the above

52.

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)

53.

How many possible values can Randomizer.next-Boolean() return?

(a)  

54.

How many times will this program print "hello"?

a)

0

b)

1

c)

2

d)

3

e)

This code will loop infinitely

55.

What statement can we use inside of a loop to end it?

(a)  

56.

Which of the following is correct loop and a half structure?

a)

while(condition){ //code }

b)

for(var i = 0; i <= 1.5; i++){ //code }

c)

while(true){ //code if(condition){ break; } //code }

d)

for(var i = 0; i < 2; i++){ //code break; //code }

57.

What is the term for the value that signals the end of user input?

a)

sentinel

b)

break

c)

-1

d)

done

58.
What 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);
59.

Which of the following correctly defines a function that increases the count by 2 until the number 8 is achieved and then refreshes to 0?

a)
b)
c)
60.

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()

61.

What does the following program do?

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


var circle = new Circle(radius);

circle.setPosition(radius, radius);

add(circle);

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

62.

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

a)

var circle = new Circle(diameter);

circle.setPosition(100,100);

add(circle);

b)

var circle = new Circle(diameter*2);

circle.setPosition(100,100);

add(circle);

c)

var circle = new Circle(diameter/2);

circle.setPosition(100,100);

add(circle);

d)

var circle = new Circle(diameter%2);

circle.setPosition(100,100);

add(circle);

63.

Which conditional statement should be used for this situation:


Karel should drop a ball and then move forward until she reaches the end of the row.

a)

if

b)

if

if

c)

if

else

d)

none of these