Oliver Eyton-Williams ee1e8abd87
feat(curriculum): restore seed + solution to Chinese (#40683)
* feat(tools): add seed/solution restore script

* chore(curriculum): remove empty sections' markers

* chore(curriculum): add seed + solution to Chinese

* chore: remove old formatter

* fix: update getChallenges

parse translated challenges separately, without reference to the source

* chore(curriculum): add dashedName to English

* chore(curriculum): add dashedName to Chinese

* refactor: remove unused challenge property 'name'

* fix: relax dashedName requirement

* fix: stray tag

Remove stray `pre` tag from challenge file.

Signed-off-by: nhcarrigan <nhcarrigan@gmail.com>

Co-authored-by: nhcarrigan <nhcarrigan@gmail.com>
2021-01-12 19:31:00 -07:00

93 lines
1.7 KiB
Markdown

---
id: 5e9ddb06ec35240f39657419
title: FizzBuzz
challengeType: 5
forumTopicId: 385370
dashedName: fizzbuzz
---
# --description--
Write a program that generates an array of integers from 1 to 100 (inclusive). But:
<ul>
<li>for multiples of 3, add <code>"Fizz"</code> to the array instead of the number</li>
<li>for multiples of 5, add <code>"Buzz"</code> to the array instead of the number</li>
<li>for multiples of 3 and 5, add <code>"FizzBuzz"</code> to the array instead of the number</li>
</ul>
# --instructions--
Your program should return an array containing the results based on the rules above.
# --hints--
`fizzBuzz` should be a function.
```js
assert(typeof fizzBuzz == 'function');
```
`fizzBuzz()` should return an Array.
```js
assert(Array.isArray(fizzBuzz()) == true);
```
Numbers divisible by only 3 should return `"Fizz"`.
```js
assert.equal(fizzBuzz()[2], 'Fizz');
```
Numbers divisible by only 5 should return `"Buzz"`.
```js
assert.equal(fizzBuzz()[99], 'Buzz');
```
Numbers divisible by both 3 and 5 should return `"FizzBuzz"`.
```js
assert.equal(fizzBuzz()[89], 'FizzBuzz');
```
Numbers not divisible by either 3 or 5 should return the number itself.
```js
assert.equal(fizzBuzz()[12], 13);
```
# --seed--
## --seed-contents--
```js
function fizzBuzz() {
}
```
# --solutions--
```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;
}
```