...And the good!


#1

var number = function(count) {

for(i>0; i<21; i++) {
console.log(i);
};

if(count % 3 === 0) {
console.log("fizz");
} else if(count % 5 === 0) {
console.log("buzz");
} else(count % 3 && count % 5 === 0) {
console.log("fizzbuzz");
};

number(3);

Oops, try again.
There was a problem with your syntax.

Something is wrong?


#2

for (var i = 0; i < 21; i++)


#3

for(i>0; i<21; i++) {

for (var i = 0; i < 21; i++)

Unfortunately, this does not solve the problem


#4

My mistake, didn't see this one as well.
} else(count % 3 == 0 && count % 5 == 0) {

Also, any particular reason you're using === instead of == ? Doesn't seem like it would make much difference here.

code:

var number = function(count) {

    for(var i=0; i<21; i++) {
        console.log(i);
    }

    if (count % 3 == 0) 
    {
        console.log("fizz");
    } 
    else if (count % 5 == 0) 
    {
        console.log("buzz");
    } 
    else if (count % 3 == 0 && count % 5 == 0) 
    {
        console.log("fizzbuzz");
    }
};

number(3);

#5

I made by your example, but the code does not work well :sweat:

Apparently the reason is global


#6

reread what I just edited my previous one, there were a few other errors that I wasn't fully paying attention to.

also if you're going for a classic fizzbuzz, you'll want those if's inside the loop something more like this:

(not actual code, just pseudo)

var fizzbuzz = function(uBound) {
    for(var i = 0; i <= uBound; i++) {
        if %3 and %5
       else if %5
       else if %3
       else
    }
};

#7

I totally copied your edited code, but it does not work

write :
Oops, try again.
It looks like you printed out the wrong number of items.


#8

What does the assignment ask you to do?


#9

Here is a link to the task:

https://www.codecademy.com/en/courses/spencer-sandbox/0/3?curriculum_id=506324b3a7dffd00020bf661


#10

The following would do it, if you have any questions about anything within the code feel free to ask.

I will do my best to explain. I like how you were going to put this within a function variable for reusability, but for the current task that seems more like a C in MoSCoW.

MoSCoW = must have ; should have; could have; won't have
It's a way to keep on task and get the job done on time~

for (var i = 1; i <= 20; i++) {
    if (i % 3 == 0 && i % 5 == 0)
        console.log("FizzBuzz");
    else if (i % 3 == 0)
        console.log("Fizz");
    else if (i % 5 == 0)
        console.log("Buzz");
    else
        console.log(i);
}

#11

Yes, it works, thank you!

I knew better to don't use the function for this job, but why I used it ..


#12

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.