JavaScript Graphics Exam Q&A: Canvas and Object Manipulation, Exams of Computer Networks

A series of questions and answers related to javascript programming, specifically focusing on graphics and canvas manipulation. It covers topics such as drawing circles, setting positions, colors, and adding elements to the screen. The questions test understanding of basic javascript concepts and their application in graphical contexts, making it a useful resource for students learning javascript graphics. It also includes questions about anchor points and text objects.

Typology: Exams

2024/2025

Available from 07/28/2025

TheHub
TheHub 🇺🇸

3.9

(35)

11K documents

1 / 3

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
JavaScript Unit 4 EXAMS WITH 100%
VERIFIED SOLUTIONS 2025/2026 STUDY
GUIDE
The following program should draw a circle on the screen:
1 function main(){
2 let circle = new Circle(40);
3 circle.setPosition(getWidth() / 2, getHeight() / 2);
4 circle.setColor("blue");
5 } main();
But when we run this code, we don't see the circle. What is missing from our main function?
We never set the circle's radius.
We need to add the line
circle.setRadius(40);
After line 4
We are setting the position of the ball to be off the canvas.We need to change line 3 to be
circle.setPosition(0, 0);
We are creating the circle incorrectly. We need to specify the width and height.We need to change
line 2 to be
let circle = new Circle(40, 40);
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);
JavaScript
after line 4
pf3

Partial preview of the text

Download JavaScript Graphics Exam Q&A: Canvas and Object Manipulation and more Exams Computer Networks in PDF only on Docsity!

JavaScript Unit 4 EXAMS WITH 100%

VERIFIED SOLUTIONS 2025/2026 STUDY

GUIDE

The following program should draw a circle on the screen: 1 function main(){ 2 let circle = new Circle(40); 3 circle.setPosition(getWidth() / 2, getHeight() / 2); 4 circle.setColor("blue"); 5 } main(); But when we run this code, we don't see the circle. What is missing from our main function? We never set the circle's radius. We need to add the line circle.setRadius(40); After line 4 We are setting the position of the ball to be off the canvas.We need to change line 3 to be circle.setPosition(0, 0); We are creating the circle incorrectly. We need to specify the width and height.We need to change line 2 to be let circle = new Circle(40, 40); 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); JavaScript after line 4

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); JavaScript after line 4 What function do you need to call to get the width of the canvas? width(); getWidth(); canvasWidth(); getCanvasWidth(); getWidth(); Where is the anchor point of a circle located? Left edge Right edge Center Top edge Bottom edge Center Where is the anchor point of a rectangle located? Top left corner Top right corner Center Bottom left corner Bottom right corner Top left corner consider the following code of a circle: 1 let circ = new Circle(50); 2 circ.setPosition(200, 200); 3 circ.setColor("blue"); 4 add(circ); JavaScript If we wanted to move the circle 10 pixels to the left, what change would we need to make? Add 10 to line 1: 1 let circ = new Circle(60); 2 circ.setPosition(200, 200); 3 circ.setColor("blue"); 4 add(circ); Subtract 10 from the first number on line 2: