Created
June 17, 2022 17:29
-
-
Save ntatko/cd427d1a545660b02119b313e26997e9 to your computer and use it in GitHub Desktop.
A basic introduction to functions in dart
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /// FUNCTIONS | |
| void main() { | |
| int sum = add(1, 3); | |
| print("$sum"); // 4 | |
| logger("stuff"); // stuff | |
| int starting = 0; | |
| double ending = toDouble(starting); | |
| print("${ending is double}"); // 0.0 | |
| } | |
| /// Add to [int]s together | |
| int add(int num1, int num2) { | |
| int summary = num1 + num2; | |
| return summary; | |
| } | |
| /// Log a [String] | |
| void logger(String toLog) { | |
| print(toLog); | |
| } | |
| /// Turn an [int] to a [double] | |
| double toDouble(int integer) { | |
| return integer.toDouble(); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment