Issue with Ultimate JavaScript Part 1: Fundamentals Exercise 3-FizzBuzz

Hello everyone. I did everything from video


but result in console olways “not a number”

I tryed to comment out line
if (typeof input !== “Number”) return “Not a number”; and function start to work properly.
What is wrong? Mosh did it the same.

please somebody help me with this one!!! Maby there is somthing with my browser?

I believe the typeof statement returns a lowercase “number” so change “Number” to “number” and I believe that should fix your problem.

thank you! i can’t believe i was so blind

1 Like

I know this is about a year old and may not be useful for you anymore. However, if someone else struggles with this, here is my way to fix it:

const output = fizzBuzz();
console.log(output);

function fizzBuzz(input) {
if (typeof input !== ‘number’)
return NaN;

if ((input % 3 === 0) && ( input % 5 === 0)
return 'fizzBuzz';

if (input % 3 === 0)
return 'fizz';

if (input % 5 === 0)
return 'Buzz';

return input;

}

Wait!? In JavaScript, writing “number” is like just saying int?

“number” is a data type and “typeof” is an operator. They are using it to verify the input they have is of type number. Javascript uses number and BigInt as the types of numbers.

Can it also be a string?

The input could be implicitly converted from type string to type number. For instance a string with the value of 10 will be implicitly converted into a number. If you tried to pass in a string with the value of “ten” then the JavaScript engine would have no way of converting a string with the value of “ten” to a number. JavaScript is a little weird about its rules for implicit conversions and there are a few gotchas you need to look out for.

You are very right about it being weird. :joy: