Skip to content

Instantly share code, notes, and snippets.

@hongsw
Last active September 14, 2022 02:56
Show Gist options
  • Save hongsw/a511fee0492d5bfb48531df7b2886123 to your computer and use it in GitHub Desktop.
Save hongsw/a511fee0492d5bfb48531df7b2886123 to your computer and use it in GitHub Desktop.
Fizz Buzz in dart
fizzBuzz(turn) {
var str = '';
if (turn % 3 == 0 && turn % 5 == 0){
str += 'FizzBuzz';
} else if (turn % 3 == 0) {
str += 'Fizz';
} else if (turn % 5 == 0) {
str += 'Buzz';
} if (str.isEmpty){
str = turn.toString();
}
return str;
}
main() {
for (int i = 1; i <= 36; i++){
print(fizzBuzz(i));
}
}
fizzBuzz(turn) {
var str = '';
if (turn % 3 == 0) {
str += 'Fizz';
}
if (turn % 5 == 0) {
str += 'Buzz';
}
if (str.isEmpty){
str = turn.toString();
}
return str;
}
main() {
for (int i = 1; i <= 36; i++){
print(fizzBuzz(i));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment