The Score

Time for a small project! In this checkpoint, you'll write a whole program on your own, using what you've learned in the first two lessons: constants and variables, arithmetic, template literals and conditions.

The exercises here are a bit different from the ones so far. The instructions say what the program should print, not how to write it. There are many correct ways, so pick the one that makes sense to you. If you get stuck, look back at the lesson where you learned what you need.

The project. You've just finished a level of a video game, and the game shows you how you did. Over three exercises, your program will work out your score, give you stars for it, and find out whether you've unlocked a secret level. Each exercise continues where the previous one ended: the editor starts with a finished program from the previous step, which may look different from yours. That's fine.

The data. The constants at the top of the program hold what happened in the level: how many coins you collected, how many enemies you defeated, and how many seconds the level took you. In a real game, the game itself would fill them in. Here, the program gets them from the constants, and your code should work with the constants, not with their numbers copied into it: when you change a constant, the program should still print the right result. To check that, each exercise also runs your program with other values, and it has to get those right too.

The task. Every coin is worth 10 points, and every defeated enemy 50 points. A fast player also gets a time bonus: 10 points for every second under 100. You took 85 seconds, 15 seconds under 100, so your bonus is 150 points. The score is all the points together. The program prints:

Coins: 370
Enemies: 300
Time bonus: 150
Score: 820

Watch out for a slow player. When the level takes 100 seconds or more, there's no bonus: with seconds = 130, the program prints Time bonus: 0, not a negative number.

A tip: remember the zoo ticket in the summary of the lesson on conditions: a variable created with let that a condition changes.

Instructions

Print the points for the coins and for the enemies, as in the example.

Below that, print the time bonus and the score.

Start programming for free

By signing up, you agree to the Terms of Service and Privacy Policy.

Or sign up with:

1/3