CodeHS Animation and Games Ultimate Exam, Exams of Technology

The CodeHS Animation and Games Ultimate Exam provides an engaging and in-depth review of animation principles, game logic, programming fundamentals, and interactive media development. Topics include object-oriented programming, event-driven design, sprite animation, collision detection, game loops, variables, conditionals, user input handling, and debugging techniques. This exam resource prepares learners for coding competitions, programming classes, and creative software development by offering interactive exercises, game-building simulations, and comprehensive practice assessments.

Typology: Exams

2025/2026

Available from 05/07/2026

nicky-jone
nicky-jone 🇮🇳

3.1

(39)

28K documents

1 / 75

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
CodeHS Animation and Games Ultimate
Exam
**Question 1.** In the CodeHS graphics library, where is the origin (0,0) located on the canvas?
A) Bottomleft corner
B) Center of the canvas
C) Topright corner
D) Topleft corner
Answer: D
Explanation: The coordinate system starts at the topleft corner, with x increasing to the right and y
increasing downward.
**Question 2.** Which method returns the width of the drawing canvas?
A) getCanvasWidth()
B) getWidth()
C) canvas.getWidth()
D) getScreenWidth()
Answer: B
Explanation: getWidth() is the builtin function that returns the horizontal size of the canvas in pixels.
**Question 3.** If you call `circle.setPosition(150, 200)`, which point of the circle is placed at (150,200)?
A) The topleft corner of the bounding box
B) The center of the circle
C) The bottomright corner of the bounding box
D) The point on the circle’s circumference at 0°
Answer: B
Explanation: setPosition sets the circle’s center coordinates.
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff
pf12
pf13
pf14
pf15
pf16
pf17
pf18
pf19
pf1a
pf1b
pf1c
pf1d
pf1e
pf1f
pf20
pf21
pf22
pf23
pf24
pf25
pf26
pf27
pf28
pf29
pf2a
pf2b
pf2c
pf2d
pf2e
pf2f
pf30
pf31
pf32
pf33
pf34
pf35
pf36
pf37
pf38
pf39
pf3a
pf3b
pf3c
pf3d
pf3e
pf3f
pf40
pf41
pf42
pf43
pf44
pf45
pf46
pf47
pf48
pf49
pf4a
pf4b

Partial preview of the text

Download CodeHS Animation and Games Ultimate Exam and more Exams Technology in PDF only on Docsity!

Exam

Question 1. In the CodeHS graphics library, where is the origin (0,0) located on the canvas? A) Bottom‑left corner B) Center of the canvas C) Top‑right corner D) Top‑left corner Answer: D Explanation: The coordinate system starts at the top‑left corner, with x increasing to the right and y increasing downward. Question 2. Which method returns the width of the drawing canvas? A) getCanvasWidth() B) getWidth() C) canvas.getWidth() D) getScreenWidth() Answer: B Explanation: getWidth() is the built‑in function that returns the horizontal size of the canvas in pixels. Question 3. If you call circle.setPosition(150, 200), which point of the circle is placed at (150,200)? A) The top‑left corner of the bounding box B) The center of the circle C) The bottom‑right corner of the bounding box D) The point on the circle’s circumference at 0° Answer: B Explanation: setPosition sets the circle’s center coordinates.

Exam

Question 4. Which property determines the drawing order of objects on the canvas? A) setZIndex() B) setLayer() C) The order in which add() is called D) setDepth() Answer: C Explanation: Objects added later are drawn on top of earlier ones. Question 5. To make a rectangle invisible without removing it from the canvas, you should use: A) rect.hide() B) rect.setVisible(false) C) rect.remove() D) rect.setOpacity(0) Answer: B Explanation: setVisible(false) toggles visibility while keeping the object in the display list. Question 6. Which of the following declares a global variable that can be accessed inside a timer callback? A) var speed = 5; B) let speed = 5; inside the callback function C) const speed = 5; inside the main program block D) int speed = 5; Answer: A

Exam

D) repeat(callback, 30); Answer: C Explanation: setTimer registers a function to be called repeatedly after the specified delay. Question 10. To stop a timer that was started with setTimer(moveBall, 20);, which call is required? A) stopTimer(moveBall); B) clearTimer(moveBall); C) cancelTimer(moveBall); D) setTimer(null, 20); Answer: A Explanation: stopTimer receives the same function reference used in setTimer. Question 11. In a physics‑based animation, which statement correctly applies a simple gravity effect to vertical velocity dy? A) dy = dy - 0.5; B) dy = dy + 0.5; C) dy = dy * 0.5; D) dy = 0.5; Answer: B Explanation: Adding a positive constant each tick simulates acceleration downward. Question 12. Which conditional correctly checks whether a sprite has moved off the right edge of the canvas? A) if (sprite.getX() > getWidth()) { … }

Exam

B) if (sprite.getX() >= getWidth()) { … } C) if (sprite.getX() < getWidth()) { … } D) if (sprite.getX() == getWidth()) { … } Answer: B Explanation: When the left side of the sprite reaches or exceeds the canvas width, it is off the right edge. Question 13. What does getElementAt(x, y) return when there is no object at the given coordinates? A) null B) undefined C) false D) 0 Answer: A Explanation: The method returns null if no graphic occupies the point. Question 14. Which logical operator should be used to test whether a key press is either the left arrow or the ‘A’ key? A) && B) || C) == D) != Answer: B Explanation: The OR operator (||) returns true when either condition is satisfied.

Exam

Question 18. What is the purpose of a function that returns a value rather than void? A) It changes the global state automatically. B) It allows the caller to receive a computed result. C) It prevents the program from compiling. D) It disables the timer. Answer: B Explanation: Returning a value lets the caller use the result in further calculations. Question 19. Which of the following best describes “top‑down design” in game programming? A) Writing all code in a single large function. B) Starting with low‑level graphics and moving upward. C) Decomposing the game into small, named functions first. D) Using only global variables. Answer: C Explanation: Top‑down design advocates planning high‑level structure then implementing details via functions. Question 20. When should you use console.log(variable) while developing a CodeHS game? A) To display the variable on the canvas. B) To permanently store the variable. C) To debug by printing its current value to the console. D) To change the variable’s type. Answer: C

Exam

Explanation: console.log outputs information to the browser console, useful for debugging. Question 21. Which statement correctly creates a blue rectangle of width 120 and height 40 positioned at (30, 70)? A) var r = new Rectangle(120, 40); r.setPosition(30, 70); r.setColor(Color.BLUE); add(r); B) var r = new Rectangle(30, 70, 120, 40); r.setColor(Color.BLUE); add(r); C) var r = new Rectangle(120, 40, 30, 70); r.setColor(Color.BLUE); add(r); D) var r = new Rectangle(120, 40); r.setLocation(30, 70); r.setColor(Color.BLUE); add(r); Answer: A Explanation: Rectangle constructor takes width and height; setPosition places the top‑left corner; setColor sets fill. Question 22. How can you make a sprite bounce off the left wall without leaving the canvas? A) if (sprite.getX() < 0) { dx = - dx; sprite.setX(0); } B) if (sprite.getX() <= 0) { dx = - dx; } C) if (sprite.getX() == 0) { dx = - dx; } D) if (sprite.getX() < 0) { dx = dx; } Answer: A Explanation: Reversing dx changes direction, and resetting X to 0 prevents the sprite from being drawn off‑screen. Question 23. Which operator returns the remainder after integer division? A) / B) %

Exam

B) Randomizer.nextPastelColor(); C) Randomizer.nextColor(200, 255); D) Randomizer.nextColor(100, 255); Answer: A Explanation: nextColor() already returns a random color; there is no built‑in pastel method, but the call satisfies the requirement. Question 27. Which statement correctly increments a score variable by the value stored in points? A) score =+ points; B) score += points; C) score = points++; D) score ++ points; Answer: B Explanation: The += operator adds the right‑hand operand to the left‑hand variable. Question 28. Which of the following loops correctly iterates five times, creating a new star each iteration? A) for (var i = 0; i < 5; i++) { createStar(); } B) for (var i = 1; i <= 5; i++) { createStar(); } C) Both A and B are correct. D) Neither A nor B is correct. Answer: C Explanation: Both loop conditions produce exactly five iterations.

Exam

Question 29. When using keyDownMethod(callback), the callback receives which parameter? A) The key code as an integer. B) A KeyboardEvent object. C) Nothing; the function has no parameters. D) A string with the key name. Answer: B Explanation: The callback is passed a KeyboardEvent that provides methods like getKeyCode(). Question 30. Which constant represents the “W” key for moving a character upward? A) Keyboard.W B) Keyboard.UP C) Keyboard.W_KEY D) Keyboard.LETTER_W Answer: A Explanation: Keyboard.W is the predefined constant for the ‘W’ key. Question 31. If a function is defined as function spawnEnemy(x, y) { … }, how would you call it to create an enemy at (250, 120)? A) spawnEnemy = (250, 120); B) spawnEnemy(250, 120); C) spawnEnemy[250, 120]; D) spawnEnemy {250, 120}; Answer: B Explanation: Functions are invoked by name followed by parentheses containing arguments.

Exam

D) speed = Math.clamp(speed, 0, 10); Answer: A Explanation: Math.min returns the smaller of the two arguments, capping speed at 10. Question 35. What will Randomizer.nextInt(5, 5) return? A) 5 B) 0 C) An error D) A random integer between 5 and 5 (always 5) Answer: D Explanation: When low and high are equal, the only possible result is the low value. Question 36. Which of the following correctly sets the background color of the canvas to light gray? A) setBackground(Color.LIGHT_GRAY); B) setBackground("lightgray"); C) setBackground(Color.gray); D) setBackground(new Color(200,200,200)); Answer: A Explanation: setBackground expects a Color constant; LIGHT_GRAY is predefined. Question 37. In CodeHS, what does the add() function return? A) The object that was added. B) The index position of the object in the display list.

Exam

C) Nothing (undefined). D) A boolean indicating success. Answer: C Explanation: add() does not return a value; it simply inserts the graphic. Question 38. Which statement correctly checks whether the variable level is either 1, 2, or 3? A) if (level == 1 || 2 || 3) { … } B) if (level == 1 || level == 2 || level == 3) { … } C) if (level in [1,2,3]) { … } D) if (level === [1,2,3]) { … } Answer: B Explanation: Each comparison must be explicit; the logical OR combines them. Question 39. How can you pause an animation without stopping the timer permanently? A) setTimer(null, 0); B) clearInterval(timerId); C) setTimer(callback, Infinity); D) Use a Boolean flag inside the callback to skip movement. Answer: D Explanation: The timer continues to fire; the flag prevents state changes, effectively pausing motion. Question 40. Which method changes the thickness of a line drawn by a Line object? A) line.setLineWidth(5);

Exam

Question 43. In a platformer, which of these best simulates friction on the horizontal velocity dx? A) dx = dx * 0.9; B) dx = dx + 0.9; C) dx = dx / 0.9; D) dx = dx - 0.9; Answer: A Explanation: Multiplying by a factor less than 1 gradually reduces speed, mimicking friction. Question 44. Which constant would you use to detect the “Enter” key in a Keyboard event? A) Keyboard.ENTER B) Keyboard.RETURN C) Keyboard.LINE_FEED D) Keyboard.OK Answer: A Explanation: Keyboard.ENTER represents the Return/Enter key. Question 45. What is the effect of calling setTimer(move, 0);? A) The callback runs continuously as fast as possible. B) The timer never fires. C) The callback fires once after 0 ms. D) It throws an error. Answer: A Explanation: A delay of 0 ms schedules the callback to execute on every iteration of the event loop, effectively a rapid loop.

Exam

Question 46. Which of the following correctly creates a function that returns the area of a rectangle given width and height? A) function area(w, h) { return w * h; } B) function area(w, h) { w * h; } C) var area = (w, h) => { w * h; }; D) function area(w, h) { console.log(w * h); } Answer: A Explanation: The function must return the computed product; option B lacks a return statement. Question 47. In CodeHS, which method checks whether a point (x, y) lies inside a given Rectangle object r? A) r.contains(x, y); B) r.isInside(x, y); C) r.pointInside(x, y); D) r.hitTest(x, y); Answer: A Explanation: Rectangle provides a contains method for point‑in‑shape testing. Question 48. When using mouseDownMethod(callback), which property of the event object gives the mouse button pressed? A) event.getButton() B) event.button C) event.getMouseButton()

Exam

A) ==

B) ===

C) === (strict equality) works for objects as well. D) Both A and B work because object comparison checks reference equality. Answer: D Explanation: In JavaScript, both == and === compare object references; they are true only when the two variables point to the same instance. Question 52. What will the following code output?

var a = 5; var b = a++; console.log(b);

A) 5 B) 6 C) 4 D) undefined Answer: A Explanation: The post‑increment operator returns the original value before incrementing, so b receives

Question 53. Which of these statements correctly disables a previously set mouse move listener? A) mouseMoveMethod(null);

Exam

B) mouseMoveMethod(undefined); C) mouseMoveMethod(off); D) There is no built‑in way; you must use a flag inside the callback. Answer: D Explanation: CodeHS does not provide a direct removal method; you control execution with a flag. Question 54. In a game, you need to display “Game Over” only once when lives reach zero. Which structure avoids repeated calls? A) if (lives == 0) { gameOver(); } placed inside the timer. B) if (lives <= 0 && !gameEnded) { gameOver(); gameEnded = true; } C) while (lives == 0) { gameOver(); } D) do { gameOver(); } while (lives == 0); Answer: B Explanation: The extra Boolean ensures the block runs only the first time the condition becomes true. Question 55. Which method clones an existing graphic so you can add a duplicate to the canvas? A) original.clone(); B) copyGraphic(original); C) original.duplicate(); D) There is no clone method; you must create a new instance manually. Answer: D Explanation: CodeHS does not provide a built‑in clone; you recreate the object with the same parameters.