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
13 answers

Trying to turn fizzbuzz into a function in python 3

I have only just started to learn python as my first language and whilst i worked out the code for fizzbuzz, i cannot for the life of me get it to do the items below. I also want it to print horizontally instead of vertically. Any help would be…
user2715061
  • 33
  • 1
  • 1
  • 5
2
votes
5 answers

Solving Fizzbuzz Using Rubys Enumerable Module?

Hey I was given the fizzbuzz task recently and I had answered with the usual, if ((i%3==0) || (i.to_s.include?('3'))) && ((i%7==0) || (i.to_s.include?('7'))) p 'Fizzbuzz' elsif (i%3==0) || (i.to_s.include?('3')) p 'Fizz' elsif (i%7==0) ||…
Conor
  • 41
  • 4
2
votes
1 answer

jQuery buttons for FizzBuzz app

I am working on a very simple JavaScript FizzBuzz app using Rails, but I can't seem to get the form and its buttons working. I know that this is very rough code, and some of it is in HTML and JavaScript as opposed to Ruby, because I am more familiar…
2
votes
3 answers

Condition in ternary operator doesn't cause any change

Here is my code sample: for $i(1..100){ if ($i%15==0){$s="Divisible by 15"} elsif($i%5==0){$s="Divisible by 5"} else {$i%3==0 ? $s="Divisible by 3" : $s=$i}; print $s."\n"} This displays partial correct results, if a number if divisible…
xan
  • 4,640
  • 13
  • 50
  • 83
1
vote
3 answers

Using List in recursive function call FizzBuzz

As a learning Exercise with the FizzBuzz code in F#. Reference with code here is working fine and looks good In above code I want to learn/use match instead of if conditions as below so have wrote below function which works for any given int…
swapneel
  • 3,061
  • 1
  • 25
  • 32
1
vote
1 answer

fizzBuzz array issues

I am doing a fizzbuzz challenge in JavaScript where I create a function that accepts a number and returns an array that is the length of the number. When there is a multiple of 3 it will say "fizz" and when there is a multiple of 5 it will say…
1
vote
1 answer

Fizzbuzz function logic not working: Output order is incorrect and logic doesn't make sense

I'm creating a simple Javascript Function that should write the numbers from 1 to n. For any multiplier of 3, it outputs "Fizz", instead of multiplers of 5 you output "Buzz", and if they happen at the same time, you should use "FizzBuzz". The output…
solo1999
  • 31
  • 3
1
vote
1 answer

Vim syntax explanation of 'Remember FizzBuzz?' VimGolf challenge

I worked my way up (or down, if you want) to the best score of Remember FizzBuzz? at VimGolf, but I have a hard time interpreting the solution: 33o FizzA4k.@.Buzz@.GI0gvgZZ I understand the…
Andreas Nasman
  • 187
  • 2
  • 10
1
vote
2 answers

What is going on in this solution to the Fizzbuzz question?

for (let number = 0; number <= 100; number++ ) { let output = "" if (number % 3 == 0) output += "Fizz" if (number % 5 == 0) output += "buzz" console.log(output || number) } I…
1
vote
2 answers

From FizzBuzz to an array

I cannot seem to figure this out whatsoever, I can use console.log(i) and get the return but cant figure out how to return as an array? Takes a number, max and returns an array that contains every number from 0 to max (not inclusive) that is…
caseyle
  • 41
  • 3
1
vote
2 answers

Why code works when I write myArray[i] and not when I save myArray[i] in a variable?

I want to populate an empty array with the classical fizzbuzz game (numbers from 1 to 100, when a number is divisible by 3 print 'Fizz, divisible by 5 print 'Buzz', divisible by both 3 and 5 print 'Fizzbuzz'). The problem is, when I write code like…
Alebacce
  • 63
  • 12
1
vote
1 answer

Creating a function in R to return a vector

I'm working on a coding project to define a function fbr(n,m) that takes integer vectors n and m as input, goes through all integers from n up to m for every element i, then returns a vector that for each number between n and m contains either a…
1
vote
1 answer

fizzbuzz question with custom (dynamic) conditions

Recently I got a different version of the "fizzbuzz question" that ask you to do this: implement function fizzBuzz(n, conditions) where n is an integer and condition is a map of key: value (number: string) you need to run on all the numbers from 1…
itay
  • 357
  • 4
  • 16
1
vote
1 answer

fizzBuzz numbers 1 to 100: (x3)Fizz, (x5)Buzz, (x3 & x5)FizzBuzz alongwith prime numbers in python

what needs to be corrected in the below code in python? e.g 91 is not prime but how it can corrected? for x in range(100): if x%3==0: print ("Fizz", x) elif x%5==0: print ("buzz",x) elif x%3==0 and x%5 == 0: …
armaghan
  • 13
  • 1
  • 5
1
vote
4 answers

PHP loop increment quirk - (FizzBuzz in one line)

I am learning PHP. I decided to adapt a solution to the famous FizzBuzz problem from Javascript to PHP, just to see how JS and PHP compare. For those who forgot what the FizzBuzz problem is : Write a short program that prints each number from 1 to…
Arti-Art
  • 25
  • 6