I have this function
function fizzbuzz(n){
}
and I want to be able to put any number in n and count backwards to 0 and console.log
on the screen. I know that a for loop
is required but I’m not exactly sure how to use it
I have this function
function fizzbuzz(n){
}
and I want to be able to put any number in n and count backwards to 0 and console.log
on the screen. I know that a for loop
is required but I’m not exactly sure how to use it
Not a for, but a while.
While this number is more than zero, -1 to this number.
PD: well, if you need a for, Jesse has the asnwer
This challenge explains in detail what you are trying to do:
https://learn.freecodecamp.org/javascript-algorithms-and-data-structures/basic-javascript/count-backwards-with-a-for-loop/
This is one option for using a for loop:
function fizzbuzz(n){
for (var i = n; i > 0; i--) {
console.log(i);
}
}
fizzbuzz(5);
-J