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 trialBenjamin Gomola
1,761 PointsIs this also a good solution?
This is whats I did:
if number % 3 == 0 && number % 5 != 0 {
println("Fizz")
} else if number % 5 == 0 && number % 3 != 0 {
println("Buzz")
} else if number % 5 == 0 && number % 3 == 0 {
println("FizzBuzz")
}
1 Answer
agreatdaytocode
24,757 PointsCheck this one out.
func checkValue(numberToCheck: Int) -> String { // #1
var valueToReturn = "" // #2
if (numberToCheck % 3 == 0 && numberToCheck % 5 == 0) {
valueToReturn = "FizzBuzz" // #3
} else if (numberToCheck % 3 == 0) {
valueToReturn = "Fizz" // #3
} else if (numberToCheck % 5 == 0) {
valueToReturn = "Buzz" // #3
} else {
valueToReturn = String(numberToCheck) // #4
}
return valueToReturn // #5
}
for var counter = 1; counter <= 100; ++counter {
println(checkValue(counter)) // #6
}
agreatdaytocode
24,757 Pointsagreatdaytocode
24,757 PointsLooks good.