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 trialJordan Gorrell
6,627 PointsFizzBuzz Function Error
Hi everyone, I wanted to take the FizzBuzz exercise in Swift a step further and make it into a function where you can select the range of numbers that the are getting "FizzBuzzed." I'm having a problem with it. I'm getting an error that says:
"ERROR at line 25, col 11: missing argument label 'high:' in call fizzBuzzer(100,150) ^ high: "
Here is my code. I'd really like to know what is going wrong with it so any help is appreciated. I'm assuming it's a simple fix and I've just missed something. Thanks
let fizz = "Fizz"
let buzz = "Buzz"
func fizzBuzzer(low: Int, high: Int) {
let counter = low...high
for count in counter {
switch count {
case count where count % 3 == 0 && count % 5 == 0:
print("\(count) makes \(fizz+buzz)")
case count where count % 3 == 0:
print("\(count) makes \(fizz)")
case count where count % 5 == 0:
print("\(count) makes \(buzz)")
default:
print("\(count)")
}
}
}
fizzBuzzer(100,150)
1 Answer
Jason Anders
Treehouse Moderator 145,860 PointsHey Jordan,
You are missing the second external variable name in your function call. If you put
fizzBuzzer(100, high: 150)
your code will execute with no errors. I could go into a very long explanation, but I would mostly be quoting the Apple Dev Docs. So, if you want, you can read up on functions and function calls at your leisure.
But, other than that... nice code. :)
Jordan Gorrell
6,627 PointsJordan Gorrell
6,627 PointsAwesome! Thanks so much :D