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 trialSamar Khanna
1,757 PointsIs my solution fine? I created a variable before this.
var gameNumber = 1...30
for inputNumber in gameNumber { if (inputNumber % 3) == 0 && (inputNumber % 5) == 0 { println("FizzBuzz") } else if (inputNumber % 3) == 0 { println("Fizz") } else if (inputNumber % 5) == 0 { println("Buzz") } else { println(inputNumber) } }
I have created a game Number variable (or array i am not sure) and then written code for the game. Is what I have done seen as good practice and is it advisable for me to carry on with this code? It works, but is what Amit did seen as better practice?
1 Answer
Meek D
3,457 PointsIt looks fine to me... but if you want you could me make more simple just by 1...30 into the loop
for inputNumber in 1...30 {
if (inputNumber % 3) == 0 && (inputNumber % 5) == 0
{
println("FizzBuzz")
}
else if (inputNumber % 3) == 0
{
println("Fizz")
}
else if (inputNumber % 5) == 0
{
println("Buzz")
}
else
{ println(inputNumber)
}
}
Samar Khanna
1,757 PointsSo i can use a separate variable right? i mean there is nothing like Amit's answer is more suitable?
Philip Ondrejack
4,287 PointsPhilip Ondrejack
4,287 PointsCheck out the markdown sheet so you're forum questions are more readable. Code in a post should look like this for readability: