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 trial
theodore eisensøe
1,107 Pointsplease help, whats up with my code
i dont get, i didn't quite understand it at start, so i went to the solution as he recommended, and took note to what the awnser should be. unfortuanly it isn't quite correct.! maybe rode something incorrect. ! please help
func fizzBuzz(n: Int) -> String { // Enter your code between the two comment markers for i in 1...100 { if (i % 3 == 0) && ( i % 5 == 0 ) { print("Fizzbuzz") } else if (i % 3 == 0) { print("Fizz") } ( i % 5 == 0 ) { print("Buzz") } else { print(i)
}
}
// End code return "(n)" }
4 Answers
Gabriel Mititelu
5,881 PointsHere it is :
func fizzBuzz(n: Int) -> String {
// Enter your code between the two comment markers
if ( n % 3 == 0) && (n % 5 == 0) {
return "FizzBuzz"
} else if ( n % 3 == 0) {
return "Fizz"
} else if ( n % 5 == 0) {
return "Buzz"
}
// End code
return "\(n)"
}
Gabriel Mititelu
5,881 PointsHello, Theodore.
You might have forgotten to write an 'else if' before the third condition ( see below) .
} else if ( i % 5 == 0 ) {
Hope this helps!
Please do make an effort next time and structure your question better. If the amount of code was even a bit larger, one might not had bothered to find the solution.
theodore eisensøe
1,107 Pointsit does not work!
func fizzBuzz(n: Int) -> String {
// Enter your code between the two comment markers
for i in 1...100 {
if (i % 3 == 0) && ( i % 5 == 0 ) {
print("Fizzbuzz")
} else if (i % 3 == 0) {
print("Fizz")
} else if ( i % 5 == 0 ) {
print("Buzz")
} else {
print(i)
}
}
// End code
return "\(n)"
}
Gabriel Mititelu
5,881 PointsHey.
I've taken these from the code challenge:
Change your variable/constant name that you are checking in each step to n. For example if (n % 3 == 0). You also don't need to define n. It is defined in the function provided.
Change all your print statements to return statements. For example: print("FizzBuzz") becomes return "FizzBuzz".
Do not worry about the default case (where the number doesn't match Fizz, Buzz, or FizzBuzz).
Also , there's no need for the loop.
I've the code written in a document. If this doesn't help still , I'll provide you with the code.
theodore eisensøe
1,107 Pointsthank you soooooooo much, i have found my mistake, and i have learned from it. i really appreciate it. have a good one