Created
November 8, 2013 18:17
-
-
Save hannaliebl/7375241 to your computer and use it in GitHub Desktop.
Solutions to the Fizzbuzz problem, so far in two languages. Both of them take a user-inputted number and then return the Fizzbuzz solution up until that number.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$(function () { | |
var user_number = prompt('Enter a number!'); | |
for (var index = 1; index <= user_number; index += 1) { | |
if (index % 3 === 0 && index % 5 === 0) { | |
document.write('fizzbuzz' + '<br />'); | |
} else if (index % 3 === 0) { | |
document.write('fizz' + '<br />'); | |
} else if (index % 5 === 0) { | |
document.write('buzz' + '<br />') | |
} else { | |
document.write(index + '<br />'); | |
} | |
} | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def fizzbuzz(number) | |
(1..number).each do |i| | |
if !(i % 3 == 0) && !(i % 5 == 0) | |
puts "#{i}" | |
elsif (i % 5 == 0) && (i % 3 == 0) | |
puts "FizzBuzz" | |
elsif i % 3 == 0 | |
puts "Fizz" | |
else i % 5 == 0 | |
puts "Buzz" | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment