Menu
Coddy logo textTech

Recap - Simple Calculations

Part of the Fundamentals section of Coddy's Dart journey — lesson 21 of 94.

challenge icon

Challenge

Easy

You're developing a simple game score calculator that tracks a player's progress through different levels. Follow these steps carefully to create your program:

Step 1: Initialize Variables

  • Create an integer variable called playerScore and set it to 100
  • Create an integer variable called currentLevel and set it to 5

Step 2: Calculate Game Statistics

Calculate and store these values in new variables:

  • Level Bonus: Multiply the current level by 20 and store the result in a variable called levelBonus
  • Power-ups Available: Each power-up costs 25 points. Use integer division (~/) to find how many complete power-ups the player can afford from their current score. Store this in powerUps
  • Remaining Points: Use the modulo operator (%) to find how many points are left after buying all possible power-ups. Store this in remainingPoints

Step 3: Update Player Score and Level

  • Add the level bonus to the player's score using the += operator
  • Increase the current level by 1 using the prefix increment operator (++currentLevel) and store this new value in a variable called newLevel
  • Subtract 15 points from the player's score using the -= operator
  • Double the player's score by multiplying it by 2 using the *= operator

Step 4: Display Results

The print statements are already provided in the code. Do not modify them. Your job is to fill in the missing variable declarations and calculations above so the output matches exactly.

Note: One of the provided print statements displays playerScore / 1.5, which performs regular (non-integer) division and produces a decimal result. This is expected — the output for that line will be 246.66666666666666.

Important: Make sure your calculations are done in the exact order specified above, as each step affects the next one.

Try it yourself

void main() {
  // Initialize player score and level
  int playerScore = ?;
  int currentLevel = ?;
  
  // Calculate level bonus, power-ups, and remaining points
  int levelBonus = ?;
  int powerUps = ?;
  int remainingPoints = ?;
  
  // Add level bonus to score using assignment shortcut
  ?;
  
  // Increment level and store new level
  int newLevel = ?;
  
  // Decrease score by 15 using assignment shortcut
  playerScore ?;
  
  // Calculate final score (multiply by 2)
  playerScore ?;
  
  // Print the results
  print('Initial score: 100');
  print('Level bonus: $levelBonus');
  print('Available power-ups: $powerUps');
  print('Remaining points: $remainingPoints');
  print('New level: $newLevel');
  print('Score after bonus and penalty: ${playerScore / 1.5}');
  print('Final score with multiplier: $playerScore');
}

All lessons in Fundamentals