function FizzBuzz(val1, val2, range) { //Init the Array let returnArray = []; //Set the first value to 0 returnArray[0] = 0; //Do fizz buzz from 1 to range. Perform modulus on each number. //Use a ternary to determine the value. for (let i = 1; i <= range; i++) { returnArray[i] = ((i % val1 == 0 ? 'Fizz' : '') + (i % val2 == 0 ? 'Buzz' : '') || i); } //Return the Array return returnArray; }
Preview:
downloadDownload PNG
downloadDownload JPEG
downloadDownload SVG
Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!
Click to optimize width for Twitter