Functions
String say(String from, String msg,
[String device = 'carrier pigeon', String mood]) {
var result = '$from says $msg';
if (device != null) {
result = '$result with a $device';
}
if (mood != null) {
result = '$result (in a $mood mood)';
}
return result;
}
print(say('Bob', 'Howdy');//Bob says Howdy with a carrier pigeon
print(say('Bob', 'Howdy','IPHONE'));//Bob says Howdy with a IPHONE
print(say('Bob', 'Howdy','IPHONE','happy'));//Bob says Howdy with a IPHONE (in a happy mood)
Conditional expressions
String playerName(String name) => name ?? 'Guest';print(playerName('Tom')); //Tomprint(playerName(null)); //Guest
Comments
Post a Comment