Final exam
Make Games with JavaScript
Before you start
- 20 questions, drawn at random from a pool of 33.
- Pass mark: 70%. Your final score is 30% practice + 70% exam.
- No time limit, but finish within 3 hours. You can move between questions before you submit.
- Failed? Review the lessons and try again: every attempt gets a new set of questions.
Question 1 of 20Choose one
Which declaration is the best choice for a value that must never change while the game runs, such as the canvas width?
Question 2 of 20Work it out
What is the value of lives after these lines run? let lives = 3; lives--; lives += 2; lives = lives * 2;
Question 3 of 20Choose one
What does "Level " + 2 + 1 produce in JavaScript?
Question 4 of 20Sort into groups
Sort each value by its JavaScript type.
Tap an item, then tap its group (or drag it there).
Question 5 of 20True or false
The condition if (score = 100) checks whether the score equals 100.
Question 6 of 20Choose one
Which condition ends the game when either the time or the health has run out?
Question 7 of 20Put in order
A grade function checks scores with else if. Arrange the conditions in the order they must be checked so every score gets the right result.
Drag the items, or use the arrow buttons, to put them in order.
- score >= 50
- score >= 75
- else (any lower score)
- score >= 90
Question 8 of 20Fill in the blanks
Fill in the blanks
In JavaScript, the && operator is read as and is true only when both sides are true, while the double-bar operator is read as and is true when at least one side is true.
Question 9 of 20Work it out
How many times does the body of for (let i = 2; i <= 10; i += 2) run?
Question 10 of 20Spot the mistake
Which of these loops will freeze the browser tab because it never ends?
Question 11 of 20Choose one
What value does this function return for total(4)? function total(n) { let t = 0; for (let i = 1; i <= n; i++) { t += i; } return t; }
Question 12 of 20True or false
Calling a function that ends with console.log(result) gives the same value back to the caller as a function that ends with return result.
Question 13 of 20Match the pairs
Match each term to the part of this code it names. function speedUp(v) { return v * 2; } speedUp(3);
Tap an answer, then tap the place where it belongs (or drag it there).
- Function name
- Parameter
- Argument
- Return value of the call
Question 14 of 20What would you do?
What would you do?
Leo's scoreboard shows NaN after the player collects a gem. His code is score = score + gemValue(); and gemValue prints 50 with console.log but has no return statement. What should he do?
Question 15 of 20Choose one
Given let items = ["map", "rope", "torch"];, what does items.length return?
Question 16 of 20Fill in the blanks
Fill in the blanks
To remove and return the last element of an array, call (). To check whether an array contains a value, call ().
Question 17 of 20True or false
Removing enemies with splice while looping forward through the array can make the loop skip an enemy.
Question 18 of 20Choose one
Which expression reads the health of the first object in an array called enemies?
Question 19 of 20Sort into groups
Which data structure fits each situation best?
Tap an item, then tap its group (or drag it there).
Question 20 of 20Choose one
On a 400 by 300 canvas, where is the point (0, 300)?
Question 21 of 20True or false
To make a character move up the screen on a canvas, you subtract from its y coordinate.
Question 22 of 20Choose one
Why should a canvas game clear or repaint the background at the start of every draw step?
Question 23 of 20Work it out
A ball starts at y = 50 with vy = 6 pixels per frame and hits nothing. What is its y after 25 frames?
Question 24 of 20Put in order
Order the lines inside a basic requestAnimationFrame game loop function.
Drag the items, or use the arrow buttons, to put them in order.
- update();
- requestAnimationFrame(gameLoop);
- draw();
Question 25 of 20What would you do?
What would you do?
In Kim's platformer, players can keep pressing jump in mid-air and fly off the top of the screen. Her jump code sets vy = -10 whenever the space bar is pressed. What is the best fix?
Question 26 of 20Choose one
In a smooth movement system, what should the keydown and keyup listeners do?
Question 27 of 20Work it out
What does Math.max(0, Math.min(100, 135)) return?
Question 28 of 20True or false
Two rectangles A and B overlap if A's left edge is less than B's right edge and A's right edge is greater than B's left edge, even if they are far apart vertically.
Question 29 of 20Work it out
Two circles have centers at (0, 0) and (6, 8). Their radii are 4 and 5. Is the distance between centers less than the sum of the radii? Enter the distance between the centers.
Question 30 of 20Choose one
What range of values can Math.floor(Math.random() * 4) produce?
Question 31 of 20Select all that apply
A player keeps collecting the same coin over and over while standing on it. Which changes would fix this? Select all that apply.
Select all that apply.
Question 32 of 20Sort into groups
In a game with start, playing and over states, which state should handle each task?
Tap an item, then tap its group (or drag it there).
Question 33 of 20True or false