WorksheetsIST CodeHS Unit 8 JavaScript Review
Total questions: 23
Worksheet time: 8mins
If the user enters a diameter value in the variable called 'diameter', how can we use this value to draw a circle with the correct diameter?
let c1 = new Circle(diameter/2)
let c2 = new Circle(diameter)
new Circle(diameter*2)
let c3 = new Circle()
When prompted for two inputs, the user enters 'Kyle' and then 'Davis'. What is printed by this JS code?
let first = readLine("What is your first name? ");
let last = readLine("What is your last name? ");
let whole = first + last;
console.log(whole);
whole
KyleDavis
Kyle Davis
Davis Kyle
What are the x,y coordinates of the center of the canvas?
0, 0
getWidth(), getHeight()
getWidth()/2, getHeight()/2
0, getHeight()*2
What are the x,y coordinates of the bottom right of the canvas?
0, 0
getWidth(), getHeight()
getWidth()/2, getHeight()/2
0, getHeight()*2
If the user enters a radius value in the variable called 'radius', how can we use this value to draw a circle with the correct radius?
let c1 = new Circle(radius/2)
let c2 = new Circle(radius)
new Circle(radius*2)
let c3 = new Circle()
What does this code do?
let rad = readInt("Enter the radius: ");
let c = new Circle(rad);
c.setPosition(getWidth()/2, rad);
add(c);
Draws a circle at the center of the canvas with a user inputted radius
Draws a circle with center at (0, 0)
Draws a circle with custom size that is centered and tangent to the top of the canvas
Draws a circle with a random radius at the top of the canvas
let circle = new Circle(16);
What is the meaning of the above code?
Creates a circle object with radius of 16 pixels
Draws a circle with center at (0, 0)
Creates a circle object with center at (0, 16)
Creates a circle object with circumference of 16 pixels
What is the meaning of the y variable?
let size = 20;
let x = 100;
let y = 150;
let ball = new Circle(size);
ball.setPosition(x, y);
The x coordinate of the center of the circle
The y coordinate of the center of the circle
The radius of the circle
The position of the circle
What is the meaning of the r variable?
let r = 50;
let x = getWidth()/2;
let y = getHeight()/2;
let cir = new Circle(r);
cir.setPosition(x, y);
The x coordinate of the center of the circle
The y coordinate of the center of the circle
The radius of the circle
The position of the circle
How would the following graphics appear on the canvas?
function main() {
addText();
addImage();
}
This will look like a website with text at the top and an image underneath
The text will probably cover over the image object
The image will probably cover over the text object
This will look like a meme with an image and a text object
We want to draw a circle on the canvas. The following code is given: what is missing?
function main() {
let circle = new Circle(40);
circle.setPosition(getWidth() / 2, getHeight() / 2);
circle.setColor("blue");
}
add(circle);
circle.setPosition(0, 0)
circle.setRadius(100);
new Circle(center);
In a program, you want to ask the user how old they are and do some math with their age. How should the prompt be written?
let age = console.log("How old are you? ");
let age = nextInt("How old are you? ");
let age = readInt("How old are you? ");
let age = readLine("How old are you? ");
A store has 100 apples. How would you store this value in a new variable using JavaScript?
var apples = 100;
num apples = 100;
apples = 100
100 == apples;
The apples in a store are to be divided evenly among 40 customers. How would you store the number of apples left over in a variable?
var leftOver = apples % 40;
var leftOver = apples / 40;
apples = apples - 40
var leftOver = 40 % apples
What is 15 % 4 ?
3
2
1
0
What is 30 % 6 ?
0
2
3
5
Which of the following variable names is both legal in JavaScript and follows good programming style?
username
15user
user name
userName
Which of the following variable names is both legal in JavaScript and follows good programming style?
numLives
10lives
num lives
num_lives
What is printed to the screen when the user enters 7?
let num = readInt("Please enter a number: ");
let calc = num * num + num;
console.log(calc);
56
98
497
84
What is printed to the screen when the user enters 6?
let num = readInt("Please enter a number: ");
let calc = num - num / 2;
console.log(calc);
3
0
-3
6
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?
console.log(distance / time);
console.log(distance / time / 60);
console.log(distance * 60 / time);
console.log(time * 60 / distance);
What line of code would print the total cost of a group of shirts if the price of each shirt is $20?
console.log(20 * shirts);
console.log(shirts / 20);
console.log(shirts % 20);
console.log(shirts + 20 + shirts);
If you want to prompt the user to enter their name, what code would accomplish this using JavaScript?
let name = readLine("What is your name? ");
let name = readInt("What is your name? ");
let age = readInt("What is your age? ");
let age = readLine("What is your age? ");
