WorksheetsCS II--June 4th Assignment
Total questions: 63
Worksheet time: 38mins
What is the term for a variable declared inside a method?
method variable
local variable
global variable
private variable
What is scope?
the part of a program where the variable exists
a minty mouthwash
a device used to aim a projectile
a device in a submarine that is used to view the surface
What characters denote a block?
< >
[ ]
{ }
( )
Where does a variable exist?
from when it's declared to the end of the block it's in
from when it's declared to the end of the method it's in
from when it's declared to the end of the class it's in
from when it's declared to the end of the program it's in
What term is used to describe data passed into/out of a program?
Variable
Loop
Constant
Parameter
Which of the following is true about global variables?
Globals should never be used.
Globals should be used as little as possible.
JavaScript will not run code that includes globals.
Globals should be used as much as possible.
Which of the following is true about function parameters?
Function parameters should never be used.
Function parameters are locals not globals.
Function parameters are globals not locals.
Function parameters should be used as little as possible.
function makePic(x , y) {
//stuff you don't need to know
}
Which is a correct function call?
If a variable has "global scope" it can be
used anywhere in the program
only used outside of a function
only used inside of a function
used outside of the program
If a variable has "local scope" it is available for use outside of its function.
TRUE
FALSE
Give the definition of variables?
Entities that appear in the program code as fixed values.
Identifier whose value can change during the course of execution of a program
It have standard, predefined meanings and must be used only for their intended purpose.
Why variables must be declared before use? Choose the suitable answer.
To tells the compiler the type of data to store
To make a program easier to understand
Select the types of variables scope.
Local variables
Global variables
Universal variables
An __________ (_) is used to assign
values to variables.
Subtraction Sign -
Equal Sign =
Addition Sign +
Parenthesis ()
The values that are passed on to the function when it is called.
Function
Identifier
Blocks
Argument
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"
Data Type
Variable
Expression
If-Statement
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?
Identify the arguments passed to the function in the following code:
function calculateSum(x, y, z) {
return x + y + z;
}
x and y
calculateSum
x, y and z
None
Identify the variable in the following code:
function Alpha(Beta) {
var Gamma = 1;
}
Alpha(Delta);
Alpha
Gamma
Beta
Delta
Which of these is a valid Karel command in JavaScript?
Choose the program below that correctly calculates the area of a rectangle (length x width) based off the user input of the measurements.
var length = readLine("Length: ");
var width = readLine("Width: ");
var area = length x width;
println("The area is: " + area);
var length = readInt("Length: ");
var width = readInt("Width: ");
var area = length x width;
println("The area is: " + area);
var length = readLine("Length: ");
var width = readLine("Width: ");
var area = length * width;
println("The area is: " + area);
var length = readInt("Length: ");
var width = readInt("Width: ");
var area = length * width;
println("The area is: " + area);
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);
21
6 + 15
615
The program will result in an error
Which command provides a random number?
Randomizer.nextNumber()
Randomizer.nextInt()
RandNumber
nextNumber.Randomizer()
Names that refer to commands, functions, variables and keyword should be written correctly, variable “A” and “a” are two different variables.
Comments
Case Sensitivity
Data Types
Statements
His name is John and he is exactly 20 years old
Which of the following is the best way to write the above statement?
if (name = "John" && age ==20 )
if (name == "John" && age ==20 )
if (name = "John" || age ==20 )
if (name == "John" || age ==20 )
var add = function(num1, num2) {
return num1 + num2;
};
The function will receive two numbers and:
What symbol represents the or operator in JavaScript?
OR
or
||
|
What is the right way to write the function:
makePancakes (Clue: this pancake will be made by putting 3 balls)
function makePancakes(){
putBall();
putBall();
putBall();
}
function makePancakes()
putBall();
putBall();
putBall();
function makePancakes: {
putBall();
putBall();
putBall();
}
function makePancakes(){
putBall();
}
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
takeBall();
move 2 times ();
move 2 times ();
putBall();
turnLeft
takeBall();
move();
move();
move();
move();
putBall();
turnLeft();
takeBall();
move();
move();
putBall();
TurnLeft{};
takeBall();
move();
move():
move():
move();
putBall();
turnLeft():
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)
True
False
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)
True
False
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")
True
False
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
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
III and IV
I and II
III only
I, II, III, and IV
In which one of these lines of code is A, B and C considered arguments?
function myFunction(A, B, C) { ... }
function myFunction() {
var A; var B; var C; }
myFunction(A, B, C);
var x = function(A, B, C) { ... };
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. thisfun(10)
B. lfc(10)
C. function thisfun(10)
D. None of the above
What will be the value of sum after this code runs?
10
4
1
40
Why do we use constant variables?
To avoid having "magic numbers" in our code
To give values a readable name, so that their purpose is clear
To let us easily change the behavior of our program by only having to change a value in one place
All of the above
Which of the following returns a random number between 1 and 10?
randomInt(1, 10)
randInt(1, 10)
Randomizer.int(1, 10)
Randomizer.nextInt(1, 10)
How many possible values can Randomizer.next-Boolean() return?
(a)
How many times will this program print "hello"?
0
1
2
3
This code will loop infinitely
What statement can we use inside of a loop to end it?
(a)
Which of the following is correct loop and a half structure?
while(condition){ //code }
for(var i = 0; i <= 1.5; i++){ //code }
while(true){ //code if(condition){ break; } //code }
for(var i = 0; i < 2; i++){ //code break; //code }
What is the term for the value that signals the end of user input?
sentinel
break
-1
done
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?
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 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);
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?
var circle = new Circle(diameter);
circle.setPosition(100,100);
add(circle);
var circle = new Circle(diameter*2);
circle.setPosition(100,100);
add(circle);
var circle = new Circle(diameter/2);
circle.setPosition(100,100);
add(circle);
var circle = new Circle(diameter%2);
circle.setPosition(100,100);
add(circle);
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.
if
if
if
if
else
none of these
