Ad

Task: “Expand words in a sentence”

   Write a reverseWords (str) function that accepts a string as input. The function should return a new line, putting the words in reverse order. If the line has punctuation marks, you can delete or leave them - at your discretion.

function reverseWords(str) {
    return str.split(" ").reverse().join(" ")
}

Task 2: "FizzBuzz"
 
  Write a function fizzBuzz (n) that takes an integer as argument.
  The function should output numbers from 1 to n to the console, replacing the numbers:

  • multiples of three - on fizz;
  • multiples of five - on buzz;
  • multiples of three and five at the same time - on fizzbuzz.

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); };
    }
};

fizzBuzz(15); //