Skip to content

Commit

Permalink
Merge pull request #14 from rosera/tastethedream-patch-12
Browse files Browse the repository at this point in the history
Update ex4-3.md
  • Loading branch information
rosera authored Dec 15, 2022
2 parents 61a75a6 + a2450b7 commit 1e51267
Showing 1 changed file with 26 additions and 11 deletions.
37 changes: 26 additions & 11 deletions ch04/ex4-3.md
Original file line number Diff line number Diff line change
@@ -1,20 +1,35 @@
# 4.3 Returning values from Functions
# 4.3 Using Optional Parameters

# Example
## Example 1

```dart
void main() {
DateTime timeLondon = getCurrentDateTime(0);
DateTime timeNewYork = getCurrentDateTime(-7);
print('London: $timeLondon');
print('New York: $timeNewYork');
printGreetingNamed();
printGreetingNamed(personName: "Rich");
printGreetingNamed(personName: "Mary", clientId: 001);
}
void printGreetingNamed({String personName = 'Stranger',
int clientId = 999}){
if (personName.contains('Stranger')) {
print('Employee: $clientId Stranger danger ');
} else {
print('Employee: $clientId $personName ');
}
}
```

DateTime getCurrentDateTime(int hourDifference) {
DateTime timeNow = DateTime.now();
DateTime timeDifference = timeNow.add(Duration(hours: hourDifference));
## Example 2

return timeDifference;
```
void main() {
printGreetingPositional("Rich");
printGreetingPositional("Rich", "Rose");
}
void printGreetingPositional(String personName, [String? personSurname]){
print(personName);
if (personSurname != null){
print(personSurname);
}
}
```

0 comments on commit 1e51267

Please sign in to comment.