Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

fizzbuzz js

function fizzBuzz2(n) {
  for (let i = 1; i <= n; i++) {
    let str = "";

    if (i % 3 === 0) str += "fizz"
    if (i % 5 === 0) str += "buzz"
    if (str === "") str = i;
  
    console.log(str);
  }
}
Comment

js fizzbuzz

function fizzBuzz(num) {
    if (num % 3 === 0 && num % 5 === 0) {
        return 'FIZZBUZZ';
    }
    if (num % 3 === 0) {
        return 'FIZZ';
    }
    if (num % 5 === 0) {
        return 'BUZZ';
    }
    return num;
}
Comment

fizzbuzz js

function fizzBuzz(n) {
  for (let i = 1; i <= n; i++) {
    let fizzbuzz = "";

    if (i % 3 === 0)
      fizzbuzz += "fizz"
    if (i % 5 === 0)
      fizzbuzz += "buzz"
    if (fizzbuzz === "")
      fizzbuzz = i;
  
    console.log(fizzbuzz);
  }
}
Comment

fizzbuzz javascript

// This is the most compact one I could make

for (let i = 1; i < 101; i++) console.log((i % 3 ? "" : "fizz") + (i % 5 ? "" : "buzz"));
Comment

PREVIOUS NEXT
Code Example
Javascript :: javascript set element width 
Javascript :: adding media queries in makeStyle material react 
Javascript :: encode in javascript 
Javascript :: find biggest word in the string 
Javascript :: mongoose unique field 
Javascript :: copy dict js 
Javascript :: TypeError: MiniCssExtractPlugin is not a constructor 
Javascript :: timestamps in mongoose 
Javascript :: vue get store state 
Javascript :: angular create guard 
Javascript :: java password regex 
Javascript :: javascript ascending and descending 
Javascript :: snap to grid 
Javascript :: react native socket io 
Javascript :: dotenv nodejs 
Javascript :: alert.alert react native style 
Javascript :: react query dev tools 
Javascript :: javascript rotate image canvas 
Javascript :: iterate 0 to n using for loop javascript 
Javascript :: javascript wait for multiple promises 
Javascript :: random integer in nodejs 
Javascript :: socket io client 
Javascript :: javascript check if json file is empty 
Javascript :: js desktop notification 
Javascript :: axios async get 
Javascript :: javascript string remove backslash 
Javascript :: javascript set width percentage update 
Javascript :: javascript validate date 
Javascript :: xmlhttprequest get request 
Javascript :: javascript error discord 
ADD CONTENT
Topic
Content
Source link
Name
6+8 =