JavaScript and Graphics

¡Supera tus tareas y exámenes ahora con Quizwiz!

What is printed to the screen when the following program is run? var num = 13 % 3; println(num);

1

What is printed to the screen if the user enters '5' when the following program is run? var userNum = readInt("Enter your favorite number: "); var calculatedNum = (userNum * userNum) + userNum; println(calculatedNum);

30

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

Draw a circle on the canvas that is always tangential to the top and left sides of the canvas

What is the output of the following program: (Assume the user enters 'Florence' then 'Fernandez'.) var first_name = readLine("What is your first name? "); var last_name = readLine("What is your last name? "); var whole_name = first_name + last_name; println (whole_name);

FlorenceFernandez

In the following code: var size = 20; var x = 100; var y = 200; var ball = new Circle(size); ball.setPosition(x, y);

The x coordinate of the center of the circle

The following program should draw a circle on the screen 1 function start(){ 2 var circle = new Circle(40); 3 circle.setPosition(getWidth() / 2, getHeight() / 2); 4 circle.setColor(Color.blue); 5 }

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 are the coordinates of the center of the window?

getWidth() / 2, getHeight() / 2

In a graphics canvas, what are the coordinates of the bottom right corner of the window?

getWidth(), getHeight()

If you were given the following variables: var distance = 2; var time = 30; 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));

Which of the following choices is a properly formed JavaScript variable name, meaning it is both legal in the JavaScript language and considered good style?

userAge

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 = readInt("How many apples would you like? ");

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/2); circle.setPosition(100,100); add(circle);

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;

A store has 20 apples in its inventory. How can you store this information in a JavaScript variable?

var numApples = 20;

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 circle = new Circle(radius); circle.setPosition(x, y); circle.setColor(color); add(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? ");


Conjuntos de estudio relacionados

Topic 10. Meiosis and Sexual Life Cycles

View Set

The Chemical basis of life- Anatomy and Physiology

View Set

RM - Exam 3: CH 10-12, Prog Review

View Set

Economics, The British Empire, Triangle Trade, and Slavery

View Set

Business Class Summer 1 EXAM #2 Chapter 6, 8, 10, 11

View Set

Unit 2 Industrialization and Progressivism (1877-1920)

View Set

AP Physics Final Exam Question Bank and Answer

View Set

Science and Technology - A2 Religious Studies

View Set