Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

JavaScript

help with js code

Only If you have time please take a look at this code also:

for (var n = 1; n <= 100; n++) {
  var output = "";
  if (n % 3 == 0)
    output += "Fizz";
  if (n % 5 == 0)
    output += "Buzz";
  console.log(output || n); //dont understand
}

I understand everything its doing and purpose except the console.log part I'm not sure what it will print and why it prints that part.

1 Answer

Hi troy,

Let's break this down. The console will print either the value of output or n. If the value of output is a false value(Empty String) it will print the value of n. If the value of the output is a true value(String has a value) then it will print the value of output.

thanks alot really well explained, thanks for your time its appreciated

No problem. Glad to help.

No problem. Glad to help.