Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to create a list of strings named fruits.
Flutter
List<String> fruits = [1]; Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using parentheses () instead of square brackets []
Using curly braces {} which create sets or maps
Using angle brackets <> which are for generics, not collections
✗ Incorrect
In Dart, lists are created using square brackets [].
2fill in blank
mediumComplete the code to access the value for key 'name' in the map.
Flutter
Map<String, String> person = {"name": "Alice", "city": "Paris"};
String name = person[1]; Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using dot notation which does not work for map keys
Using parentheses which is invalid syntax
Using an index number which is for lists, not maps
✗ Incorrect
To get a value from a map by key, use square brackets with the key as a string.
3fill in blank
hardFix the error in the code to add an item to the set.
Flutter
Set<int> numbers = {1, 2, 3};
numbers[1](4); Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using append or push which are list methods
Using insert which is not a method for sets
Trying to add items with assignment instead of a method
✗ Incorrect
Sets use the add() method to add new items.
4fill in blank
hardFill both blanks to create a map from a list of keys and a list of values.
Flutter
List<String> keys = ["a", "b", "c"]; List<int> values = [1, 2, 3]; Map<String, int> map = Map.fromIterables([1], [2]);
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Swapping keys and values
Using undefined variables like items or elements
Passing only one argument instead of two
✗ Incorrect
Map.fromIterables takes two iterables: one for keys and one for values.
5fill in blank
hardFill all three blanks to create a set from a list and add a new item.
Flutter
List<int> nums = [1, 2, 3]; Set<int> numSet = [1](nums); numSet.[2](4); bool hasFour = numSet.[3](4);
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using List.of instead of Set.from
Using wrong method names like insert or push
Checking membership with wrong methods
✗ Incorrect
Use Set.from to create a set from a list, add() to add an item, and contains to check membership.