Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

JavaScript Introduction to Programming Control Structures Loops

extra credit ("fizzbuzz") - external information

hello,

i noticed that a lot of people solve the "fizzbuzz" riddle. but some operators that essential in order to solve the problem is not included in the course, like ==. now, i happen to know those things, but i was trying to solve the problem only with the tools provided in the course...

so, my question is where's everyone here get they extra knowledge?

4 Answers

I can pull this answer if we are not suppose to post extra credit results. Please just message me if this is the case. Using just the concepts discussed in this lesson and an explanation of mod, we can answer this puzzle.

Concept: if statements evaluate based truthiness. Concept: else statement evaluates anything that returns false from the if statement Concept: True in javascript can be true, anything that is not 0 or null etc... Concept: False in Javascript can be false, 0, "" etc...

So without any other logical operators (I initially just used a "!." We can nest our if statement and reverse the logic.

for (var counter=100; counter; counter = counter - 1) {
    if (counter % 5) {
            if (counter % 3) {

            console.log(counter);
            } else {
            console.log("fizz");
            }

    } else {
        if (counter % 3) {
        console.log("buzz");
        } else {
            console.log("fizzbuzz");
        }
    }


}

yeah,, some external codes apart from this course such as "else if " is really helpful

for (counter=100; counter; counter=counter-1)  
{
        if (counter%3==0&&counter%5==0) {console.log('buzz fizz');}
        else if (counter%5==0) {console.log('fizz');}
        else if (counter%3==0) {console.log('buzz');}
        else {console.log(counter);}
}

thank you, isaac, for your answer.

i just have a few notes:

a. the program you wrote is running backwards from 100 to 1, while in puzzle it seems that the goal is to make the program print the numbers from 1 to 100.

b. the code you wrote still contain some parts that wasn't included in the course, like "-=". also, in the hint, they didn't include the idea of leaving the "a%b" without an equal sign.

now, i get that this is a self learning area. i'm not complaining about that. i simply want to know where everybody else getting their completion of their knowledge.

thanks again.

Thanks for keeping me on my toes.

Response to a. The problem never stated the order that the 1 through 100 number range had to go. Just that each number had to be printed. I think in this case going backwards still counts. Although, a little more fiddling could have the sequence increasing.

Response to the first part of b. You are also correct that they didn't use "-=" and have corrected that.

Response to the second part of b. In terms of leaving a%b without an equal sign, I refer you to two parts of the course. In the video If/Else at around minute 4:30 they talk about what are considered "truthy" values and "falsey" values. Truthy values being anything that isn't 0 or its like.

The other hint would be in the description of the Extra Credit Problem where it describes what modulus does. By having a value that is not 0, it would be a truthy statement.

hi,

first of all, you might consider commenting to the main-question and not to my last comment, because as you can see, i can't reply to your comment now. also, i'm not able to +1 you.

anyway, back to our discussion, you're right. the hints is all over, but since i am not an expert yet, i need an additional resources. that was my question from the beginning.

thanks anyway, i'll try my luck at general discussion area.