Files
freeCodeCamp/curriculum/challenges/english/blocks/daily-coding-challenges-javascript/69f8c998d78ad3171a0713be.md
T

1.5 KiB

id, title, challengeType, dashedName
id title challengeType dashedName
69f8c998d78ad3171a0713be Challenge 291: FizzBuzz Count 28 challenge-291

--description--

Given a start and end number, count the number of fizz and buzz appearances in the range (inclusive).

  • Numbers divisible by 3 count as a fizz.
  • Numbers divisible by 5 count as a buzz.
  • Numbers divisible by both 3 and 5 count as both a fizz and a buzz.

Return an object or dictionary with the counts in the format: { fizz, buzz }.

--hints--

fizzBuzzCount(1, 11) should return {fizz: 3, buzz: 2}.

assert.deepEqual(fizzBuzzCount(1, 11), {fizz: 3, buzz: 2});

fizzBuzzCount(14, 41) should return {fizz: 9, buzz: 6}.

assert.deepEqual(fizzBuzzCount(14, 41), {fizz: 9, buzz: 6});

fizzBuzzCount(24, 100) should return {fizz: 26, buzz: 16}.

assert.deepEqual(fizzBuzzCount(24, 100), {fizz: 26, buzz: 16});

fizzBuzzCount(-635, -14) should return {fizz: 207, buzz: 125}.

assert.deepEqual(fizzBuzzCount(-635, -14), {fizz: 207, buzz: 125});

fizzBuzzCount(-5432, 6789) should return {fizz: 4074, buzz: 2444}.

assert.deepEqual(fizzBuzzCount(-5432, 6789), {fizz: 4074, buzz: 2444});

--seed--

--seed-contents--

function fizzBuzzCount(start, end) {

  return start;
}

--solutions--

function fizzBuzzCount(start, end) {
  let fizz = 0, buzz = 0;

  for (let i = start; i <= end; i++) {
    if (i % 3 === 0) fizz++;
    if (i % 5 === 0) buzz++;
  }

  return { fizz, buzz };
}