Silver Challenge Solutions


#21

import Cocoa

for i in 1…100 {

if i % 3 == 0 && i % 5 == 0 {
    print("FIZZ BUZZ")
    continue
}

if i % 3 == 0 {
    print("FIZZ")
    continue
}

if i % 5 == 0 {
    print("BUZZ")
    continue

} if else {
print (i)
}
}

This is what I came up with but I cannot figure out what’s wrong with this code… help!


#22

“if else” doesn’t make any sense. Change that to “else”.


#23

Jim, never do performance in a playground. They’re not optimized for that and more than likely will give you false positives. You really need to do it in a dedicated program, and set it to run a few 100K times. I can help you walk through how to do that if you want.


#24

this i a good answer, maybe l’m smart too… but …


#25

import Cocoa
var count = 1;
for _ in 1 … 15 {
count += 1 ;
if count % 3 == 0 && count % 5 == 0 {
print(“fizz buzz”);
}else if count % 3 == 0 {
print (“fizz”);
}else if count % 5 == 0{
print(“buzz”);
}else{
print(count);
}
}