Ad
Code
Diff
  • function fizzBuzz(num) {
        for (let i=1;i <= num; i++) {
            if (i%3===0) {console.log("fizz");};
            if (i%5===0) {console.log("buzz");}
            if (i%15===0) {console.log("fizzbuzz");}
        }
    };
    
    fizzBuzz(15); // 
    • function fizzBuzz(num) {
    • for (let i=1;i <= (num); i++) {
    • let fb = '';
    • if (i%3===0) {fb = fb + 'fizz'};
    • if (i%5===0) {fb = fb + 'buzz'};
    • if (fb==='') { console.log(i); } else { console.log(fb); };
    • for (let i=1;i <= num; i++) {
    • if (i%3===0) {console.log("fizz");};
    • if (i%5===0) {console.log("buzz");}
    • if (i%15===0) {console.log("fizzbuzz");}
    • }
    • };
    • fizzBuzz(15); //