Double points

ChallengeKeeping count

On a bonus level, everything the hero collects is worth double. This script should work out the score, but it gets it wrong.

What should happen

  1. The hero has 12 coins and 3 gems. That is 15 things.
  2. Everything is doubled.
  3. The score is 30.
ThingsThe sumScore
12 coins and 3 gems(12 + 3) × 230

What happens now

The script writes Score: 18 in the log. It doubled the gems, but not the coins.

What the script doesThe sumScore
Times first: 3 × 2 is 6. Then 12 + 612 + 3 × 218

How to fix it

The plus has to be done before the times. You know how to make that happen.

  1. Press Code, at the top left of the code box, if it is not picked already.
  2. Find the line that starts @score is.
  3. Put a bracket before @coins and another after @gems.

No problems detected

Goals0 of 1 passed

  • The score is 30: not checked yet

Press Play and make every goal pass. A goal is checked when its moment in the game comes.

Test it

Press Run. The goal under the code box gets a tick when the score is 30.

If the log saysWhat to check
Score: 18The brackets are missing
A red note under the scriptA bracket is missing its partner. Every ( needs a )

Make every goal and every test pass to finish this section.