Recap - Simple Decisions
Part of the Fundamentals section of Coddy's Dart journey — lesson 34 of 94.
Challenge
MediumCreate a program that analyzes a person's eligibility for different types of driver's licenses based on their age and experience:
- Declare an integer variable
agewith a value of 19 - Declare an integer variable
drivingExperiencewith a value of 2 (representing years) - Declare a boolean variable
hasPassedTestwith a value oftrue - Implement the following license eligibility rules:
- If the person is under 16, print:
Status: Not eligible for any driving license. Must be at least 16 years old. - If the person is 16 or 17:
- If they passed the test, print:
Status: Eligible for a provisional license. - If they haven't passed the test, print:
Status: Not eligible yet. Need to pass the driving test. - If the person is 18 or older:
- If they have less than 1 year of driving experience, print:
Status: Eligible for a beginner license. - If they have 1-3 years of driving experience, print:
Status: Eligible for a regular license. - If they have more than 3 years of driving experience, print:
Status: Eligible for an advanced license. - After determining the license type, print a summary line with the following format:
Summary: Age: 19, Experience: 2 years, Test Passed: true
Your output must match the exact format shown above, but with the appropriate license status based on the values of the variables.
Try it yourself
void main() {
// Declare your variables here
int age = 19;
int drivingExperience = 2;
bool hasPassedTest = true;
// Implement the license eligibility rules
// Print the summary
print('Summary: Age: $age, Experience: $drivingExperience years, Test Passed: $hasPassedTest');
}All lessons in Fundamentals
4Operators Part 2
Comparison OperatorsLogical ANDLogical ORLogical NOTType Test OperatorsRecap - Making Comparisons7Working with Strings
String ConcatenationString InterpolationMulti-line StringsString PropertiesBasic String Methods10Collections - Maps Basics
What are Maps?Creating a MapAccessing Values by KeyKey-Value PairsGetting Map SizeGetting KeysGetting ValuesChecking if a Key Exists13Null Safety In Depth
Understanding NullNullable TypesNon-Nullable TypesNull Assertion OperatorLate InitializationRecap - Handling Null Safely16Fundamentals Challenges
Challenge: List of calculationChallenge: Sum of numbersChallenge: Find product2Variables and Basic Data Types
What are Variables?StringsIntegers (int)Doubles (double)Booleans (bool)Type Inference with 'var'Final VariablesConstant VariablesNaming ConventionsBasic Null SafetyRecap - Declaring Variables8Control Flow - Loops
The 'for' LoopThe 'while' LoopThe 'do-while' LoopUsing 'break' in LoopsUsing 'continue' in LoopsRecap - Repeating Code3Operators Part 1
Arithmetic OperatorsInteger DivisionModulo OperatorIncrement and DecrementAssignment ShortcutsRecap - Simple Calculations6Control Flow - Decision Making
The 'if' StatementThe 'else' StatementThe 'else if' StatementRecap - Simple DecisionsNested 'if' StatementsThe 'switch' Statement9Collections - Lists Basics
What are Lists?Creating a ListAccessing by IndexGetting List LengthAdding ElementsRemoving ElementsChecking if a List is EmptyIterating Over a List12Functions Advanced
Optional Positional ParametersNamed ParametersRequired Named ParametersDefault Parameter ValuesRecap - Function Parameters15Project: Simple Calculator
Setting UpDeclaring Number