Challenge: List of calculation
Part of the Fundamentals section of Coddy's Dart journey — lesson 92 of 94.
Challenge
EasyIn this challenge, you'll practice displaying formatted calculation results to users. You have a list of calculation results that need to be displayed in a user-friendly format.
Your task is to complete the displayResults function that takes a list of calculation results and displays them with proper formatting. Each result should show the calculation type, the numbers used, and the result value.
Complete the code to properly display all calculation results from the provided list.
Try it yourself
void main() {
// List of calculation results
List<Map<String, dynamic>> calculationResults = [
{
'type': 'Addition',
'num1': 10,
'num2': 5,
'result': 15
},
{
'type': 'Subtraction',
'num1': 20,
'num2': 7,
'result': 13
},
{
'type': 'Multiplication',
'num1': 4,
'num2': 6,
'result': 24
}
];
// Call the function to display results
displayResults(calculationResults);
}
// TODO: Complete this function to display all calculation results
void displayResults(List<Map<String, dynamic>> results) {
print('Calculation Results:');
print('-------------------');
// TODO: Loop through the results list and display each calculation
// in the format: "[Type]: [num1] and [num2] = [result]"
}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