Created with <3 with dartpad.dev.
Last active
September 14, 2022 02:56
-
-
Save hongsw/a511fee0492d5bfb48531df7b2886123 to your computer and use it in GitHub Desktop.
Fizz Buzz 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
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)); | |
} | |
} |
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
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