// from https://www.codecademy.com/resources/blog/20-code-challenges/
// Printing numbers 1 through 100 (inclusive), but for multiples of 3, we will print "Fizz" instead. If it's a multiple of 5: "Buzz". If it's a multiple of both 3 and 5: "FizzBuzz".
// We will detect the multiples of 3 and/or 5 by seeing if the quotient of the current number divided by three changes when floored (to determine whether it went into it fully, producing an integer output).
function count(){
var o = "";
for(var xint = 1;xint < 101;xint++){
if(xint / 3 == Math.floor(xint / 3)
&& xint / 5 == Math.floor(xint / 5)) o += "FizzBuzz\n"; // both 3 & 5
else if(xint / 3 == Math.floor(xint / 3)) o += "Fizz\n"; // 3
else if(xint / 5 == Math.floor(xint / 5)) o += "Buzz\n"; // 5
else o += xint + "\n";
}
console.log(o);
}
No comments:
Post a Comment