iOS Swift Collections and Control Flow Control Flow With Conditional Statements FizzBuzz Challenge

ali aboutaleb
ali aboutaleb
4,025 Points

Cant get this right... i have checked all the discussions and i cant get it!! Can any one help?

ughhh

fizzBuzz.swift
if (n % 3 == 0) && (n % 5 == 0) { return ("FizzBuzz") }

else if (n % 3 == 0) { return ("Fizz") }

else if (n % 5 == 0) { return ("Buzz") }

2 Answers

Dave Harker
PRO
Dave Harker
Pro Student 15,507 Points

Hi ali aboutaleb,

Couldn't see anything wrong so I literally copied your code and pasted it into the challenge between the comments they designated. Worked without issue.

Perhaps try again? Happy coding, :dizzy:
Dave

Alex Busu
PRO
Alex Busu
Pro Student 11,819 Points

Hey there, why are you putting brackets on your strings. Also for this solution if I can make a suggestion, try to add strings together instead of hard checking for all possible combinations. e.g.

var result = ""
if(n%3 == 0) { result+="Fizz" }
if(n%5 == 0) { result+="Buzz" }
result.count > 0 ? result : "\(n)"