diff --git a/curriculum/challenges/_meta/rosetta-code/meta.json b/curriculum/challenges/_meta/rosetta-code/meta.json index 9e1bc2ab57..2f64115eec 100644 --- a/curriculum/challenges/_meta/rosetta-code/meta.json +++ b/curriculum/challenges/_meta/rosetta-code/meta.json @@ -216,6 +216,10 @@ "5992e222d397f00d21122931", "Fibonacci word" ], + [ + "5e9ddb06ec35240f39657419", + "FizzBuzz" + ], [ "5a7dad05be01840e1778a0d1", "Fractran" diff --git a/curriculum/challenges/english/08-coding-interview-prep/rosetta-code/fizzbuzz.english.md b/curriculum/challenges/english/08-coding-interview-prep/rosetta-code/fizzbuzz.english.md new file mode 100644 index 0000000000..7dd39b15bb --- /dev/null +++ b/curriculum/challenges/english/08-coding-interview-prep/rosetta-code/fizzbuzz.english.md @@ -0,0 +1,86 @@ +--- +title: FizzBuzz +id: 5e9ddb06ec35240f39657419 +challengeType: 5 +forumTopicId: 385370 +--- + +## Description +
+ +Write a program that generates an array of integers from 1 to 100 (inclusive). But: + + +
+## Instructions +
+ +Your program should return an array containing the results based on the rules above. +
+ +## Tests +
+ +```yml +tests: + - text: fizzBuzz should be a function. + testString: assert(typeof fizzBuzz=='function'); + - text: fizzBuzz() should return an Array. + testString: assert(Array.isArray(fizzBuzz())==true); + - text: Numbers divisible by only 3 should return "Fizz". + testString: assert.equal(fizzBuzz()[2], "Fizz"); + - text: Numbers divisible by only 5 should return "Buzz". + testString: assert.equal(fizzBuzz()[99], "Buzz"); + - text: Numbers divisible by both 3 and 5 should return "FizzBuzz". + testString: assert.equal(fizzBuzz()[89], "FizzBuzz"); + - text: Numbers not divisible by either 3 or 5 should return the number itself. + testString: assert.equal(fizzBuzz()[12], 13); + +``` + +
+ +## Challenge Seed +
+ +
+ +```js +function fizzBuzz() { + // Good luck! +} +``` + +
+ +
+ +## Solution +
+ +```js +function fizzBuzz() { + let res=[]; + for (let i =1; i < 101; i++) { + if (i % 3 === 0 && i % 5 === 0) { + res.push("FizzBuzz"); + } + else if (i % 3 === 0) { + res.push("Fizz"); + } + else if (i % 5 === 0) { + res.push("Buzz"); + } + else { + res.push(i); + } + } + return res; +} +``` + +