Menu
Coddy logo textTech

Logical AND

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

The logical AND operator (&&) returns true only when both expressions are true, otherwise false.

void main() {
  bool isAdult = true;
  bool hasLicense = true;
  
  bool canDrive = isAdult && hasLicense;
  
  print('Can this person drive? $canDrive');
}
void main() {
  int age = 25;
  double savings = 5000.0;
  
  bool isEligibleForLoan = (age >= 18) && (savings >= 1000.0);
  
  print('Is eligible for loan? $isEligibleForLoan');
}
challenge icon

Challenge

Easy

Create a game eligibility checker using the logical AND (&&) operator:

  1. Declare an integer variable age with a value of 15
  2. Declare a boolean variable hasParentalConsent with a value of true
  3. Declare a boolean variable hasCompletedTutorial with a value of false
  4. Declare a boolean variable canPlayGame that is true ONLY if:
    • The player is 18 or older, OR
    • The player is at least 13 years old AND has parental consent
  5. Declare a boolean variable canAccessBonus that is true ONLY if:
    • The player canPlayGame AND has completed the tutorial
  6. Print the results with the EXACT following format:
Player age: 15
Has parental consent: true
Completed tutorial: false
Can play game: true
Can access bonus content: false

Your output must match this exact format.

Cheat sheet

The logical AND operator (&&) returns true only when both expressions are true, otherwise false.

bool canDrive = isAdult && hasLicense;

You can combine multiple conditions:

bool isEligible = (age >= 18) && (savings >= 1000.0);

Try it yourself

void main() {
  // Declare your variables here
  int age = ?;
  bool hasParentalConsent = ?;
  bool hasCompletedTutorial = ?;
  
  // Check if player can play the game
  bool canPlayGame = age >= ? || (age >= ? && hasParentalConsent);
  
  // Check if player can access bonus content
  bool canAccessBonus = canPlayGame ? hasCompletedTutorial;
  
  // Print the results
  print("Player age: $age");
  print("Has parental consent: $hasParentalConsent");
  print("Completed tutorial: $hasCompletedTutorial");
  print("Can play game: $canPlayGame");
  print("Can access bonus content: $canAccessBonus");
}
quiz iconTest yourself

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

All lessons in Fundamentals