Boss fight

Section Exercises

Practice what you learned in Control Flow & Functions

Complete these coding exercises to reinforce your understanding of operators, conditions, loops, and functions.

0 / 18 cleared

Cleared0%
1

Operators & Conditions

Practice basic operators and conditional logic

1

Challenge 1

Easy

Write code that checks if a number is even or odd and prints the result.

starter.dart
1int number = 42;
2// Your code here
2

Challenge 2

Easy

What is the result of: 10 % 3 in Dart?

Your answer
3

Challenge 3

Easy

Create a variable that uses the null-aware operator (??) to provide a default value of "Guest" if name is null.

starter.dart
1String? name = null;
2String displayName = // Your code here
4

Challenge 4

Medium

Use the ternary operator to assign "Pass" if score >= 60, otherwise "Fail".

starter.dart
1int score = 75;
2String result = // Your code here
5

Challenge 5

Easy

What does the expression (5 > 3 && 2 < 1) evaluate to?

Your answer
6

Challenge 6

Medium

Write code that categorizes a score into grades: A (90+), B (80-89), C (70-79), D (60-69), F (<60).

starter.dart
1int score = 85;
2// Your code here
7

Challenge 7

Medium

Create a switch statement that prints the day name based on a number (1=Monday, 2=Tuesday, 3=Wednesday).

starter.dart
1int day = 2;
2// Your code here
8

Challenge 8

Medium

In Dart, can you use strings in switch statements?

Your answer
2

Loops

Master different types of loops

1

Challenge 1

Easy

Write a for loop that prints numbers from 1 to 10.

starter.dart
1// Your code here
2

Challenge 2

Easy

Use a for-in loop to print each item in this list: ["Apple", "Banana", "Orange"]

starter.dart
1List<String> fruits = ["Apple", "Banana", "Orange"];
2// Your code here
3

Challenge 3

Medium

What is the key difference between while and do-while loops?

Your answer
4

Challenge 4

Medium

Write a loop that prints only even numbers from 1 to 10.

starter.dart
1// Your code here
5

Challenge 5

Hard

Create a while loop that finds and prints the first number divisible by both 3 and 5, starting from 1.

starter.dart
1int num = 1;
2// Your code here
3

Functions

Create and use functions

1

Challenge 1

Easy

Write a function called greet that takes a name and returns "Hello, [name]!"

starter.dart
1// Your function here
2

Challenge 2

Easy

Create a function that calculates the area of a rectangle (width * height).

starter.dart
1// Your function here
3

Challenge 3

Medium

What is the difference between required positional and optional positional parameters?

Your answer
4

Challenge 4

Medium

Write a function with named parameters that has default values for width and height (both default to 1).

starter.dart
1// Your function here
5

Challenge 5

Medium

Convert this function to an arrow function: int double(int x) { return x * 2; }

starter.dart
1// Your arrow function here

Loot collected

Key takeaways
  • Practice writing code regularly to improve your skills
  • Start with simpler exercises before moving to complex ones
  • Understanding the logic behind solutions is key