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
Practice basic operators and conditional logic
Write code that checks if a number is even or odd and prints the result.
1int number = 42;2// Your code hereWhat is the result of: 10 % 3 in Dart?
Create a variable that uses the null-aware operator (??) to provide a default value of "Guest" if name is null.
1String? name = null;2String displayName = // Your code hereUse the ternary operator to assign "Pass" if score >= 60, otherwise "Fail".
1int score = 75;2String result = // Your code hereWhat does the expression (5 > 3 && 2 < 1) evaluate to?
Write code that categorizes a score into grades: A (90+), B (80-89), C (70-79), D (60-69), F (<60).
1int score = 85;2// Your code hereCreate a switch statement that prints the day name based on a number (1=Monday, 2=Tuesday, 3=Wednesday).
1int day = 2;2// Your code hereIn Dart, can you use strings in switch statements?
Master different types of loops
Write a for loop that prints numbers from 1 to 10.
1// Your code hereUse a for-in loop to print each item in this list: ["Apple", "Banana", "Orange"]
1List<String> fruits = ["Apple", "Banana", "Orange"];2// Your code hereWhat is the key difference between while and do-while loops?
Write a loop that prints only even numbers from 1 to 10.
1// Your code hereCreate a while loop that finds and prints the first number divisible by both 3 and 5, starting from 1.
1int num = 1;2// Your code hereCreate and use functions
Write a function called greet that takes a name and returns "Hello, [name]!"
1// Your function hereCreate a function that calculates the area of a rectangle (width * height).
1// Your function hereWhat is the difference between required positional and optional positional parameters?
Write a function with named parameters that has default values for width and height (both default to 1).
1// Your function hereConvert this function to an arrow function: int double(int x) { return x * 2; }
1// Your arrow function here