Skip to content

Instantly share code, notes, and snippets.

@hiteshsahu
Created December 16, 2023 09:11
Show Gist options
  • Save hiteshsahu/0473e74ff906f7061d7954d87069eb43 to your computer and use it in GitHub Desktop.
Save hiteshsahu/0473e74ff906f7061d7954d87069eb43 to your computer and use it in GitHub Desktop.

Revisions

  1. hiteshsahu created this gist Dec 16, 2023.
    53 changes: 53 additions & 0 deletions gistfile1.txt
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,53 @@
    'use strict';

    process.stdin.resume();
    process.stdin.setEncoding('utf-8');

    let inputString = '';
    let currentLine = 0;

    process.stdin.on('data', function(inputStdin) {
    inputString += inputStdin;
    });

    process.stdin.on('end', function() {
    inputString = inputString.split('\n');

    main();
    });

    function readLine() {
    return inputString[currentLine++];
    }



    /*
    * Complete the 'fizzBuzz' function below.
    *
    * The function accepts INTEGER n as parameter.
    */

    function fizzBuzz(n) {
    // Write your code here
    for(let i=1; i<=n; i++){

    const isMultipleOf3 = i%3 ==0
    const isMultipleOf5 = i%5 ==0

    if(isMultipleOf3 && isMultipleOf5 ) print("FizzBuzz")
    else if(isMultipleOf3 && !isMultipleOf5) print("Fizz")
    else if(!isMultipleOf3 && isMultipleOf5) print("Buzz")
    else print(i)
    }
    }

    function print(message){
    console.log(message)
    }

    function main() {
    const n = parseInt(readLine().trim(), 10);

    fizzBuzz(n);
    }