Menu
Coddy logo textTech

Booleans (bool)

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

Booleans (bool type) have only two values: true or false. They represent yes/no conditions in programs.

void main() {
  bool isRaining = true;
  print(isRaining);
}

Boolean values are written without quotation marks. You can reassign them:

void main() {
  bool isCompleted = false;
  print(isCompleted);
  
  // Change the value
  isCompleted = true;
  print(isCompleted);
}
challenge icon

Challenge

Beginner

Create a Dart program that works with boolean values to track the status of a simple game character:

  1. Declare a boolean variable named isAlive and set it to true
  2. Declare a boolean variable named hasWeapon and set it to false
  3. Declare an integer variable named healthPoints and set it to 100
  4. Declare a double variable named speed and set it to 7.5
  5. Print all variables with descriptive labels in the EXACT following format:
Character Status:
Alive: true
Armed: false
Health: 100
Speed: 7.5

Your output must match this exact format.

Cheat sheet

Booleans (bool type) have only two values: true or false. They represent yes/no conditions in programs.

bool isRaining = true;
bool isCompleted = false;

Boolean values are written without quotation marks and can be reassigned:

bool isCompleted = false;
isCompleted = true; // Change the value

Try it yourself

void main() {
  // Declare your variables here
  bool isAlive = ?;
  bool hasWeapon = ?;
  int healthPoints = ?;
  double speed = ?;
  
  // Print the character status
  print("Character Status:");
  print("Alive: " + isAlive.toString());
  print("Armed: " + hasWeapon.toString());
  print("Health: " + healthPoints.toString());
  print("Speed: " + speed.toString());
}
quiz iconTest yourself

This lesson includes a short quiz. Start the lesson to answer it and track your progress.

All lessons in Fundamentals