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

Basic JavaScript - Extra Credit

This is my solution for the 'loops' extra credit assignment in the JavaScript Basics Course.

for (var counter=100; counter; counter = counter -1) {

    var divideby3 = counter % 3;
    var divideby5 = counter % 5;

    if (divideby5 < 1 && divideby3 < 1) {
        console.log("fizzbuzz")
    }
    else if (divideby5 < 1) {
        console.log("buzz")
    }
    else if (divideby3 < 1) {
        console.log("fizz")
    }
    else {
        console.log(counter);       
    } 
}

Here is the html for it

<!DOCTYPE html>
<html lang="en">
  <head>
    <title>Introduction to Programming</title>
    <style>
            html {
                background: #fafafa;
                font-family: sans-serif;
            }
            h1 {
                background: tomato;
                padding: 5px 5px 5px 15px;
                color: white;
                border-radius: 7px;
                border-bottom: 3px solid red;
            }
            h2 {
                color: tomato;
                font-style: italic;
                position: relative;
                top: -15px;
                left: 15px;
        </style>
    <script src="myscript.js"></script>
  </head>  
  <body>
    <h1>Introduction to Programming</h1>
    <h2>with JavaScript</h2>
  </body>
</html>

If you want to subtract one from the variable each time the loop runs you can type

counter-- 

or

counter -= 1

.

for (var counter=100; counter; counter = counter -1) {

Why are you using for lopp when this looks like a while loop will work better here?

    var divideby3 = counter % 3;
    var divideby5 = counter % 5;

    if (divideby5 < 1 && divideby3 < 1) {
        console.log("fizzbuzz")
    }
    else if (divideby5 < 1) {
        console.log("buzz")
    }
    else if (divideby3 < 1) {
        console.log("fizz")
    }
    else {
        console.log(counter);       
    } 
}

This look nice.However you may wanna use case for this one!

for (var counter=100; counter; counter = counter -1) {

Why are you using for lopp when this looks like a while loop will work better here?

    var divideby3 = counter % 3;
    var divideby5 = counter % 5;

    if (divideby5 < 1 && divideby3 < 1) {
        console.log("fizzbuzz")
    }
    else if (divideby5 < 1) {
        console.log("buzz")
    }
    else if (divideby3 < 1) {
        console.log("fizz")
    }
    else {
        console.log(counter);       
    } 
}

This look nice.However you may wanna use case for this one!