Summary - Data types
- Dart course
- Beginner
- Lesson 18/116
- 5 min
Combine int, double, String and bool to write a calculation card.
Summary - Data types
In this group you learned Dart's basic data types: int (integer), double (decimal), String (text), bool (boolean) and dynamic (flexible).
You also saw type inference with var and runtime type checks with the is operator. We will practice with two small tasks.
In later lessons we will use these types in function parameters, collections and class fields. The foundation is laid here.
Practice Calculation card
Inside void main() declare int quantity = 3, double price = 9.99, String name = 'Pen'. Print all three with print.
Starter code
// Declare variables and print themSample solution
void main() {
int quantity = 3;
double price = 9.99;
String name = 'Pen';
print(quantity);
print(price);
print(name);
}Expected output
3 9.99 Pen
Practice Final calculation card
Inside void main() declare an int, a double and a String for a product. Set values to 5, 12.5 and Notebook. Print with print.
Starter code
// Complete the programSample solution
void main() {
int quantity = 5;
double price = 12.5;
String name = 'Notebook';
print(quantity);
print(price);
print(name);
}Expected output
5 12.5 Notebook
Questions and answers
Review the lesson questions together with their answers. To test yourself, solve the lesson interactively.
1 Which type fits a product price?
- double Correct answer
- int
- String
- bool
Explanation: Price is decimal; double fits.
2 Text type
____ name = 'Alex';
String name = 'Alex';
Explanation: Text is stored in this type.
3 Match all types
| Term | Meaning |
|---|---|
int |
Integer |
double |
Floating-point |
String |
Text |
bool |
Boolean |