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

My take on the extra credit code

for (var counter = 0; counter <= 100; counter = counter + 1) {

//If statement checking if the number is divisible by both 5 and 3
if (counter % 3 == 0 && counter % 5 == 0) {
    console.log("fizzbuzz");
}
//If statement checking if counter is divisible by 3 only
 else if (counter % 3 == 0) {
    console.log("fizz");
} 
//If statement chacking if counter is divisible by 5 only
else if (counter % 5 == 0) {
    console.log("buzz");
} 
else {
    console.log(counter);
}

}

That's how i did it. Let me know if you've gotten anything different or any ways i could improve my own!

PS. If anyone knows how to make it skip 0 so that it doesn't print out "fizzbuzz" on the number 0 please school me.

1 Answer

Hi Adam,

If you want to skip 0, you just need to start counter at 1 instead of 0.

for (var counter = 1; counter <= 100; counter = counter + 1)

Doh!