4 examples of 'fizzbuzz in javascript' in JavaScript

Every line of 'fizzbuzz in javascript' code snippets is scanned for vulnerabilities by our powerful machine learning engine that combs millions of open source libraries, ensuring your JavaScript code is secure.

All examples are scanned by Snyk Code

By copying the Snyk Code Snippets you agree to
this disclaimer
14function getFizzBuzz(obj, arr) {
15 let newArray = [];
16 let sizeOfArray = arr.length;
17 let strOutput = '';
18 for(let i=0; i < sizeOfArray; i++) {
19 strOutput = '';
20 for(let key in fizzbuzz_obj) {
21 if(arr[i] % key === 0) {
22 strOutput += fizzbuzz_obj[key];
23 }
24 }
25 if(strOutput === '') {
26 strOutput = arr[i];
27 }
28 // console.log(strOutput);
29 newArray.push(strOutput);
30 }
31 return newArray;
32}
Important

Use secure code every time

Secure your code as it's written. Use Snyk Code to scan source code in minutes – no build needed – and fix issues immediately. Enable Snyk Code

5generate(input: number): string {
6 var output = '';
7
8 if (input % 3 === 0) {
9 output += FizzBuzz.fizz;
10 }
11
12 if (input % 5 === 0) {
13 output += FizzBuzz.buzz;
14 }
15
16 return output === '' ? input.toString() : output;
17}
16function fizzbuzz(n) {
17 for (let i = 1; i <= n; i++) {
18 if (i % 15 === 0) {
19 console.log('fizzbuzz');
20 } else if (i % 3 === 0) {
21 console.log('fizz');
22 } else if (i % 5 === 0) {
23 console.log('buzz');
24 } else {
25 console.log(i);
26 }
27 }
28}
7calculate(input: number): string {
8 return this.rules
9 .filter(r => r.appliesTo(input))
10 .map(r => r.result)
11 .join('-') || input.toString()
12}

Related snippets