Wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

IST CodeHS Unit 8 JavaScript Review

Total questions: 23

Worksheet time: 8mins

Name
Class
Date
1.

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?

a)

let c1 = new Circle(diameter/2)

b)

let c2 = new Circle(diameter)

c)

new Circle(diameter*2)

d)

let c3 = new Circle()

2.

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

a)

whole

b)

KyleDavis

c)

Kyle Davis

d)

Davis Kyle

3.

What are the x,y coordinates of the center of the canvas?

a)

0, 0

b)

getWidth(), getHeight()

c)

getWidth()/2, getHeight()/2

d)

0, getHeight()*2

4.

What are the x,y coordinates of the bottom right of the canvas?

a)

0, 0

b)

getWidth(), getHeight()

c)

getWidth()/2, getHeight()/2

d)

0, getHeight()*2

5.

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?

a)

let c1 = new Circle(radius/2)

b)

let c2 = new Circle(radius)

c)

new Circle(radius*2)

d)

let c3 = new Circle()

6.

What does this code do?

let rad = readInt("Enter the radius: ");

let c = new Circle(rad);

c.setPosition(getWidth()/2, rad);

add(c);

a)

Draws a circle at the center of the canvas with a user inputted radius

b)

Draws a circle with center at (0, 0)

c)

Draws a circle with custom size that is centered and tangent to the top of the canvas

d)

Draws a circle with a random radius at the top of the canvas

7.

let circle = new Circle(16);

What is the meaning of the above code?

a)

Creates a circle object with radius of 16 pixels

b)

Draws a circle with center at (0, 0)

c)

Creates a circle object with center at (0, 16)

d)

Creates a circle object with circumference of 16 pixels

8.

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

a)

The x coordinate of the center of the circle

b)

The y coordinate of the center of the circle

c)

The radius of the circle

d)

The position of the circle

9.

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

a)

The x coordinate of the center of the circle

b)

The y coordinate of the center of the circle

c)

The radius of the circle

d)

The position of the circle

10.

How would the following graphics appear on the canvas?

function main() {

addText();

addImage();

}

a)

This will look like a website with text at the top and an image underneath

b)

The text will probably cover over the image object

c)

The image will probably cover over the text object

d)

This will look like a meme with an image and a text object

11.

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");

}

a)

add(circle);

b)

circle.setPosition(0, 0)

c)

circle.setRadius(100);

d)

new Circle(center);

12.

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?

a)

let age = console.log("How old are you? ");

b)

let age = nextInt("How old are you? ");

c)

let age = readInt("How old are you? ");

d)

let age = readLine("How old are you? ");

13.

A store has 100 apples. How would you store this value in a new variable using JavaScript?

a)

var apples = 100;

b)

num apples = 100;

c)

apples = 100

d)

100 == apples;

14.

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?

a)

var leftOver = apples % 40;

b)

var leftOver = apples / 40;

c)

apples = apples - 40

d)

var leftOver = 40 % apples

15.

What is 15 % 4 ?

a)

3

b)

2

c)

1

d)

0

16.

What is 30 % 6 ?

a)

0

b)

2

c)

3

d)

5

17.

Which of the following variable names is both legal in JavaScript and follows good programming style?

a)

username

b)

15user

c)

user name

d)

userName

18.

Which of the following variable names is both legal in JavaScript and follows good programming style?

a)

numLives

b)

10lives

c)

num lives

d)

num_lives

19.

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

a)

56

b)

98

c)

497

d)

84

20.

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

a)

3

b)

0

c)

-3

d)

6

21.

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?

a)

console.log(distance / time);

b)

console.log(distance / time / 60);

c)

console.log(distance * 60 / time);

d)

console.log(time * 60 / distance);

22.

What line of code would print the total cost of a group of shirts if the price of each shirt is $20?

a)

console.log(20 * shirts);

b)

console.log(shirts / 20);

c)

console.log(shirts % 20);

d)

console.log(shirts + 20 + shirts);

23.

If you want to prompt the user to enter their name, what code would accomplish this using JavaScript?

a)

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

b)

let name = readInt("What is your name? ");

c)

let age = readInt("What is your age? ");

d)

let age = readLine("What is your age? ");