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 trialConor Mosier
3,866 Pointsmakes me want to quit.
func fizzBuzz(n: Int) -> String { // Enter your code between the two comment markers for n in 1...100 { if (n % 3 == 0) && (n % 5 == 0){ print ("Fizzbuzz") } else if (n % 3 == 0){ print ("Fizz") } else (n % 5 == 0) { print("Buzz") } else { print(i) } // End code return "(n)" }
literally pulled this damn code from the solution video the exact same and it failed for the same errors that i encountered on my own approach. treehouse deeply lacks in the "practice area" we should be taught step by step how to solve these quizzes/challenges then once we have a firm idea on how to solve them then test us. like you know normal education. sorry I'm so pissed but I'm sick of wasting time on these when they feel like the "test is nothing that we were taught" syndrome. or just too far ahead from what we learned
func fizzBuzz(n: Int) -> String {
// Enter your code between the two comment markers
for n in 1...100 {
if (n % 3 == 0) && (n % 5 == 0){
print ("Fizzbuzz")
} else if (n % 3 == 0){
print ("Fizz")
} else (n % 5 == 0) {
print("Buzz")
} else {
print(i)
}
// End code
return "\(n)"
}
1 Answer
Jennifer Nordell
Treehouse TeacherHi there! Your logic is solid and there's only one syntax error. The syntax error is here:
else (n % 5 == 0)
An else
statement doesn't take a conditional. It's what happens after everything else has failed. You meant to write :
else if (n % 5 == 0)
... just like the line before it.
The primary problem comes with following the instructions of the challenge. They are picky. They even note that in the challenge instructions and give the reason why they are so picky for this particular challenge.
While these are very specific directions, they allow me to verify your solution precisely over a large number of possible answers.
You started off great and made sure that your variable was named n
per the challenge requirements. But there were other instructions that you missed.
Step 3: Change all your print statements to return statements. For example: print("FizzBuzz") becomes return "FizzBuzz".
You are printing the results and this challenge needs you to return the results.
Also, your code resides inside a for
loop, but the challenge instructions say this:
The challenge also does not need you to loop over a range of values (using for or while). I'll take care of that.
This means that the for
loop should be removed. So if I edit your code just slightly, it passes the challenge because, as stated, your logic is solid.
Hope this helps!