Questions tagged [fizzbuzz]

a game, algorithm and a common programming task of replacing any number divisible by three with the word "fizz", and any number divisible by five with the word "buzz"

Fizzbuzz is a game used to teach children division. Implementing an algorithm for that game is sometimes used as an interview task.

https://en.wikipedia.org/wiki/Fizz_buzz

290 questions
2
votes
1 answer

FizzBuzz: num%15 being first versus num%3 being first

I just want to know why 'FizzBuzz only works when num % 15 === 0 is first as opposed to when num % 3 === 0 is first. For example: for (let num = 1; num <= 100; num++) { if (num % 15 === 0) { console.log('FizzBuzz'); } else if (num % 5 === 0) { …
2
votes
2 answers

Java FizzBuzz recursive solution

Attempting a FizzBuzz recursive solution in Java to return a list of Strings with n iterations. For example, n = 4 should output ["1","2","Fizz", 4]. However, with my current code the output is just ["4"]. Why is my solution not executing the…
alexjs000
  • 85
  • 9
2
votes
1 answer

c# fizzbuzz auto number generator

I have just made a simple game of fizz buzz( its where numbers go up and if divisible by 3 it is called fizz and if divisible by 5 its called buzz, and if divisible by both its called fizz buzz) and it works, however, I need to press enter to get…
James
  • 37
  • 1
2
votes
2 answers

Playing FizzBuzz in Angular

I have successfully implemented FizzBuzz in angular, and was wondering if I am doing everything according to Angular Best Practices. My questions: 1) Is there any way to set $scope.display in the factory directly instead of returning something? so…
devdropper87
  • 4,025
  • 11
  • 44
  • 70
2
votes
1 answer

Implementing input variables in functions in Haskell

This is a continuation to my previous post. I'm creating a FizzBuzz function that allows 3 parameters to be entered. However, this isn't just the standard FizzBuzz program. This one allows for 2 divisors while implementing an upper range. So if…
Rocket Risa
  • 383
  • 2
  • 16
2
votes
4 answers

Difference between if vs if else if in fizzbuzz

I tried implementing fizzbuzz in C++ and am confused by the different outputs the following code samples produce: int main() { int val1 = 1; while (val1 < 101) { if (val1 % 15 == 0) cout << "FizzBuzz\n"; if (val1…
kevin
  • 147
  • 2
  • 11
2
votes
1 answer

How can I optimize (or improve) this Fizz Buzz script?

//Script to find numbers that are the power of 3 and 5 from 1 to 100 using % Modulus operator - when it finds a number that can be the power of 3 or 5 it outupts FizzBuzz... example hosted on my blog…
user2276553
2
votes
1 answer

FizzBuzz textContent issue

I'm using the old FizzBuzz exercise, and utilizing textContent, trying to load a page with each of the values listed one after the other, vertically. Right now I'm getting this instead:…
2
votes
2 answers

FizzBuzz doesn't fizz or buzz using case/when

I'm trying to understand how to use a conditional expression in a Ruby case/when statement. This code seems like it should work, but it only prints 1 through 100 inclusive, and never prints "Fizz", "Buzz" or "FizzBuzz". #!/usr/bin/env…
Michael Hampton
  • 9,737
  • 4
  • 55
  • 96
2
votes
1 answer

What is this Bash Syntax in FizzBuzz Example

I just found the following FizzBuzz example on Hacker News and it uses a piece of syntax I'm finding it difficult to search for for num in {1..100} ; do out="" (( $num % 3 == 0 )) && out="Fizz" (( $num % 5 == 0 )) && out="${out}Buzz" echo…
Peter R
  • 414
  • 2
  • 10
2
votes
1 answer

Using different string types with if else constructs in Rust

The following is obviously not working: fn main() { for i in range(1i, 101) { println!("{}", if i % 15 == 0 { "Fizzbuzz" } else if i % 5 == 0 { "Buzz" } else if i % 3 == 0 { "Fizz" …
OderWat
  • 5,379
  • 3
  • 29
  • 31
2
votes
1 answer

Total newb here and other fizzbuzz issue

I'm trying to write a looping fizzbuzz code that ends with the user_input's number. So far the code works, but it loops the number of times you put in for the user_input, not end at the user_input's limit. For example, if I type in 25, it will loop…
2
votes
3 answers

Why does this golang function _not_ run forever?

I wanted to try the FizzBuzz test (Why can't programmers program), and used Go. It's basically looping from 1 to 100, and printing "Fizz" when the loop counter is divisible by 3, "Buzz" when divisible by 5, "FizzBuzz" when divisible by both and else…
Kiril
  • 6,009
  • 13
  • 57
  • 77
2
votes
3 answers

Why isn't my "Fizz Buzz" test in R working?

I heard this was a common interview question, any ideas what is off here, thank you. for(i in 1:100){ if(i%15==0){ print('fizzbuzz') } else if (i%3==0){ print("fizz") } else if (i%5==0) { …
Benzle
  • 373
  • 3
  • 9
  • 18
2
votes
12 answers

Fizz Buzz in Ruby for dummies

Spoiler alert: I am a true novice. Tasked with figuring out fizz buzz in ruby for a class and while I have found more than a few versions of code that solve the problem, my understanding is so rudimentary that I cannot figure out how these…
user3290752
  • 21
  • 1
  • 1
  • 2