Last active
November 6, 2020 15:33
-
-
Save kamalx/e0be52fd078687a877903b9976af1d2a to your computer and use it in GitHub Desktop.
99 bottles of beer on the wall (song lyrics)
This file contains 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
String bWhat(int n) { | |
return n != 1 ? 'bottles' : 'bottle'; | |
} | |
void main() { | |
for(var i = 99; i > 0; i--) { | |
((){ | |
int num = i; | |
String b = bWhat(num); | |
String howManyWhat = num !=0 ? '$num ' : 'no '; | |
howManyWhat += '$b of beer'; | |
print('$howManyWhat on the wall, $howManyWhat'); | |
String doWhat = 'Take one down and pass it around'; | |
String leftWhat = num !=1 ? '${num-1} ' : 'no '; | |
leftWhat += '${bWhat(num-1)} of beer on the wall.'; | |
print('$doWhat, $leftWhat \n'); | |
})(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
https://dartpad.dartlang.org/e0be52fd078687a877903b9976af1d2a