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 trialshane reichefeld
Courses Plus Student 2,232 Pointscan someone help me ive gone over this in 3 different ways with 3 different submition questions.....
please help me i cant continue till this works and ive tried and it should have worked the first two ways i did it
func fizzBuzz(n: Int) -> String {
// Enter your code between the two comment markers
let ght = [
n%3 ==0: "Fizz"
n%5 ==0: "Buzz"
]
for (key, value) in ght {
switch key{
case n%3 ==0, n%5 ==0: print("FizzBuzz")
case n%3 ==0: print("Fizz")
case n%5 ==0: print("Buzz")
}
}
// End code
return "\(n)"
}
1 Answer
Christopher Augg
21,223 Pointshey Shane,
You will not want to do any loops for this. The function gets one Int value and determines which string it should return (Not print). You will want place something like the following (??? = what should you use?) into the provided code where it says to place it:
if ??? {
return "FizzBuzz"
} else if ??? {
return "Fizz"
} else if ??? {
return "Buzz"
}
Regards,
Chris
Jose Patarroyo
2,953 PointsJose Patarroyo
2,953 PointsHello Shane,
I don't quite remember this challenge, but this is what I see in your code:
I believe you are trying to use a dictionary named ght, it wasn't written properly, you have to use ":" to separate the key from the value; besides, I don't really think you need a dictionary for this task. This function expects a String out as a result, I know you probably don't know yet what I'm talking about (you will soon enough), but the important thing is you are not supposed to use the "print command", instead use return follow by the appropriate string Ex: return "Fizz", or return "Buzz". One last thing, you are using a Switch statement but you are not being exhaustive, meaning that you don't have a default scenario that should be used whenever the expression that is being evaluated doesn't fit any of your cases.
I hope this helps you fix your code, as you know, there are several answers for this challenge, you just have to take into account Passan's steps for this challenge.