Menu
Coddy logo textTech

Recap - Declaring Variables

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

challenge icon

Challenge

Easy

In this challenge, you'll create a simple data model for a weather application using various variable types and concepts you've learned.

Complete the following tasks:

  1. Create a String variable named cityName with the value "New York"
  2. Create an int variable named temperature with the value 28
  3. Create a double variable named humidity with the value 0.65
  4. Create a bool variable named isSunny with the value true
  5. Create a variable using var named weatherCondition with the value "Partly Cloudy"
  6. Create a final variable named countryCode with the value "US"
  7. Create a const variable named WEATHER_API_VERSION with the value "v1.0" (use proper naming convention for constants)
  8. Create a nullable String variable named weatherWarning with the value null
  9. Print all variables with descriptive labels in the exact format shown in the expected output
  10. Update weatherWarning to "Heat Advisory" and print it again with the same label

Your output must match the exact format shown in the expected output.

Try it yourself

void main() {
  // Declare all required variables
  String cityName = ?;
  int temperature = ?;
  double humidity = ?;
  bool isSunny = ?;
  var weatherCondition = ?;
  final countryCode = ?;
  const String WEATHER_API_VERSION = ?;
  String? weatherWarning = ?;
  
  // Print all variables with labels
  print("Weather Information:");
  print("City: ?");
  print("Temperature: $temperature°C");
  print("Humidity: ?");
  print("Sunny: ?");
  print("Condition: ?");
  print("Country: ?");
  print("API Version: ?");
  print("Warning: ?");
  
  // Update weatherWarning and print it again
  weatherWarning = ?;
  print("Warning: ?");
}

All lessons in Fundamentals