Skip to content

Instantly share code, notes, and snippets.

@hannaliebl
Created November 8, 2013 18:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hannaliebl/7375241 to your computer and use it in GitHub Desktop.
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.
$(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 />');
}
}
});
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