mirror of
https://github.com/freeCodeCamp/freeCodeCamp.git
synced 2026-02-24 20:01:39 -05:00
1.7 KiB
1.7 KiB
id, title, challengeType, forumTopicId, dashedName
| id | title | challengeType | forumTopicId | dashedName |
|---|---|---|---|---|
| 5e9ddb06ec35240f39657419 | FizzBuzz | 1 | 385370 | fizzbuzz |
--description--
Write a program that generates an array of integers from 1 to 100 (inclusive). Pero:
- para múltiplos de 3, suma
"Fizz"a la matriz en lugar del número - para múltiplos de 5, suma
"Buzz"a la matriz en lugar del número - para múltiplos de 3 y 5, suma
"FizzBuzz"a la matriz en lugar del número
--instructions--
Su programa debe devolver una matriz que contenga los resultados según las reglas anteriores.
--hints--
fizzBuzz debe ser una función.
assert(typeof fizzBuzz == 'function');
fizzBuzz() debe devolver una matriz.
assert(Array.isArray(fizzBuzz()) == true);
Los números divisibles por solo 3 deberían regresar"Fizz".
assert.equal(fizzBuzz()[2], 'Fizz');
Los números divisibles por solo 5 deberían regresar "Buzz".
assert.equal(fizzBuzz()[99], 'Buzz');
Los números divisibles por 3 y 5 deberían regresar "FizzBuzz".
assert.equal(fizzBuzz()[89], 'FizzBuzz');
Los números que no son divisibles por 3 o 5 deben devolver el número en sí.
assert.equal(fizzBuzz()[12], 13);
--seed--
--seed-contents--
function fizzBuzz() {
}
--solutions--
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;
}