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
-1
votes
2 answers

javascript FizzBuzz / if else statements

Here is the code: var i = 0; for (i = 1; i <= 20; i++) { if (i % 5 === 0 && i % 3 === 0) { console.log("FizzBuzz"); } else if (i % 5 === 0) { console.log("Buzz"); } else if (i % 3 === 0) { console.log("Fizz"); …
-1
votes
1 answer

How do I match types in Haskell so the expected type matches the actual type?

Attempting to implement fizzBuzz with some command line using optparse-applicative. import Options.Applicative data Args = Args { firstDivisor :: Int, secondDivisor :: Int, upperBound :: Int } fizzBuzz :: Args ->…
-1
votes
4 answers

How to find all numbers divisible by another number in swift?

How do I find all the numbers divisible by another number in swift that have a remainder of 0? This is a Fizzbuzz related question. Lets say that... let number = 150 And I want to do something like... print("Fizz") // for all the numbers where the…
-1
votes
1 answer

FizzBuzz game involcing C$

The following error is: Errors and Failures: 1) Test Failure : fizzbuzz.FizzBuzzTest.TestInputFifteen Expected string length 8 but was 4. Strings differ at index 0. Expected: "FizzBuzz" But was: "Buzz" -----------^ at…
Dan
  • 11
  • 2
-1
votes
3 answers

Why no fizzbuzz being printed out?

This is my code. I am not getting any Fizz buzz printed. I am only getting numbers. Could anyone explain why? Thanks printOut = ""; for (var x=1; x < 101 ; x++) { switch(x) { case((x%3) == 0): printOut+="\n"+ "Fizz" ; …
-1
votes
1 answer

Vanilla JS Fizzbuzz does not work

I am trying to add a new LI looping from 1 to 100 and then display either the count var or fizz/buzz/fizzbuzz. Got it to work in Jquery, but not in pure JS. The code:

Fbuzz

    function…
    damiano celent
    • 721
    • 6
    • 12
    -1
    votes
    1 answer

    How would I write a header and implementation file for FizzBuzz in Objective-C?

    EDIT TO ADD: SOLVED AT BOTTOM, see main.m I wanted to try the FizzBuzz Challenge in Objective-C since I'm teaching myself the language. I easily coded it in main.m, but I wondered if there was a way to code it via a header and implementation file.…
    -1
    votes
    2 answers

    jQuery breaking my fizzbuzz, why?

    Trying to solve the fizzbuzz problem in javascript with a little html. I want to put the answers in a
      and display them on the page. To do this, I need to take the fizz-buzz's and somehow add them in a
    • element to the UL, with a prepend or…
    yeet6
    • 1
    • 1
    -1
    votes
    1 answer

    Breakdown of the cost and time required for Fizzbuzz in worst case

    The Fizz-Buzz function (in pseudocode) takes any positive integer n. I'm especially curious about the algebraic breakdown of the cost and time required of the if-else statement. I know its worst case running time is O(n). Fizz-Bizz(n) for i = 1 to…
    MNRC
    • 263
    • 1
    • 11
    -1
    votes
    2 answers

    How can I take advantage of Sass, for example, in rendering FizzBuzz?

    I managed to write FizzBuzz in pure CSS as kind of personal Hello World to learn how to write stylesheets. I'd like to do the same with Sass, but I'm not sure how I could make use of Sass syntax or semantics to improve on this. Currently, I've got a…
    apennebaker
    • 681
    • 2
    • 8
    • 17
    -1
    votes
    5 answers

    understanding the fizz buzz in C#

    When solving "fizz-buzz" in C# using a "while" loop, I found out that first I should find the multiples of both 3 and 5 (multiples of 15) and then go to the multiples of 3 and 5 like below. int myval = 0; while (myval < 100) { myval = myval +…
    scylla
    • 65
    • 2
    • 9
    -2
    votes
    2 answers

    FizzBuzz Function in Rust

    This is my code: fn main() { fn fizz_buzz<'a>(i: i32) -> &'a str { if i % 15 == 0 { "FizzBuzz" } else if i % 5 == 0 { "Buzz" } else if i % 3 == 0 { "Fizz" } else { &i.to_string() } } …
    dpokey
    • 64
    • 6
    -2
    votes
    2 answers

    FizzBuzz into array with javascript into an array not working properly

    This is my first question so sorry if it's dumb. I'm trying to do the classic FizzBuzz exercise in the console using javascrypt, putting the changes into an array for 1 to 100. So far: let nums = []; for (let i = 1; i <= 100; i++) { …
    -2
    votes
    1 answer

    how do I call a void function in my main function in c?

    void fizzBuzz(int n) { for (int i = 0; i < n; i++){ if (i % 3 == 0 && i % 5 == 0){ printf("FizzBuzz\n");} else if (i % 3 == 0 && i % 5 != 0){ printf("Fizz\n");} else if (i % 3 != 0 && i % 5 == 0){ …
    -2
    votes
    2 answers

    Print multiple of 3 and 5 in bash script

    Write a short program that prints each number from 1 to 100 on a new line. • For each multiple of 3, print "Fizz" instead of the number. • For each multiple of 5, print "Buzz" instead of the number. • For numbers which are multiples of both 3 and 5,…
    Kachi
    • 17
    • 2