Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Pushing and Incrementing the value in an array using a function

I am learning through an online course but the instructor computers seems to return the output as expected whereas my computer simply doesn’t return me anything. also tried using online compilers

I am trying to make a "FizzBuzz" program.
Thanks for help anyways

var output = [];

var count = 1 ;

function fizzBuzz() {
output.push(count);
 count++;

console.log(output);


}

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

call fizzBuzz() at the end of the script 🙂
also keep in mind that after the execution you will have [ 1 ]
cause you’re pushing the value before incrementing

the code:

var output = [];

var count = 1 ;

function fizzBuzz() {
output.push(count);
 count++;

console.log(output);


}
fizzBuzz()
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading