Blog

Some FizzBuzzes (Buzz-eye?) (NIKITA HASIS)

On December 30, 2014, in Syndicated, by Association for Software Testing
0

In Ruby:

for n in 1..20
	if (n % 3 == 0) && (n % 5 == 0)
		puts "#{ n } means FizzBuzz"
	elsif (n % 3 == 0) 
		puts "#{ n } means Fizz"
	elsif (n % 5 == 0)
		puts "#{ n } means Buzz"
	else
		puts n
	end
end

And in Swift:

// Playground - noun: a place where people can play

import UIKit

for n in 1...20 {
    if (n % 3 == 0) && (n % 5 == 0){
        println("\(n) is FizzBuzz")
    }else if (n % 3 == 0) {
        println("\(n) is Fizz")
    } else if (n % 5 == 0) {
        println("\(n) is Buzz")
    } else {
        println("\(n) is \(n)")
    }
}

 

Gonna try a case solution next.

 

Comments are closed.


Looking for something?

Use the form below to search the site:


Still not finding what you're looking for? Drop a comment on a post or contact us so we can take care of it!