Menu
Coddy logo textTech

Challenge: List of calculation

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

challenge icon

Challenge

Easy

In 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