Created
July 7, 2022 11:01
-
-
Save namdiemefo/be9c5261b9834b7314c1111f874b0d3e to your computer and use it in GitHub Desktop.
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
void main() { | |
doFizzBuzz(); | |
} | |
doFizzBuzz() { | |
// initialize variables | |
num fizzNumber = 0; | |
num buzzNumber = 0; | |
String word = ""; | |
num x = 1; | |
while (x <= 100) { | |
// increment values | |
fizzNumber++; | |
buzzNumber++; | |
// attach and reset values | |
if (fizzNumber == 3) { | |
word += "Fizz"; | |
fizzNumber = 0; | |
} | |
if (buzzNumber == 5) { | |
word += "Buzz"; | |
buzzNumber = 0; | |
} | |
word.isEmpty ? print(x) : print(word); | |
word = ""; | |
x++; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment