Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialWill Feldman
3,121 PointsWould the following code also work?
var number = 3
if number % 5 == 0 && number % 3 == 0 {
println("FizzBuzz")
}
else if number % 3 == 0 {
println("Fizz")
}
else if number % 5 == 0 {
println("Buzz")
}
And as you change the var "number" it would print the correct result.
3 Answers
Franciscus Agnew
23,912 PointsHello Will,
The short answer... the code would work, but it may not work the way you intended!
The short solution...
var number = 3
if number % 5 == 0 && number % 3 == 0 {
println("FizzBuzz")
}
else if number % 5 == 0 {
println("Fizz")
}
else if number % 3 == 0 {
println("Buzz")
}
else {
do something...
}
Good Luck,
Franciscus
Lukas Muller
7,347 PointsGot the same result. Awesome!
John Scully
1,018 PointsYour code is identical to where I started and will definitely work if you pass it each individual value. But the real power of code is in the ability to automate so that the computer does all the work for you.
Simply replace your var with "for numbers in 1...50 {"
and you've got it. Just have to close the curly braces at the end of your code.
Jenna McCarter
4,391 PointsJenna McCarter
4,391 PointsThat looks pretty good to me.