I put together a fizzbuzz algorithm and for some odd reason the part of the function that should return "not a number" when the value assigned to the input seems to take every input and return "not a number" If I keep the if statement with the NaN at the top of the function, nothing gets by it. If I put it before the return input, the function will run fine if I put a # divisible by 3 or 5, or both, but once it hits the NaN logic, it stop and console logs Not a number. I'm sure I'm making an obvious mistake, but I can't see it. Can anyone let me know what I'm doing wrong? enter image description here
Asked
Active
Viewed 111 times
-1
-
3Please post code as text, not as image. – Apr 04 '21 at 15:52
1 Answers
0
You just written condition checks in reverse
function fizzBuzz(input) {
if (typeof input !== 'number') {
return 'Not a number';
}
if ((input % 3 === 0) && (input % 5 === 0)) {
return 'FizzBuzz';
}
if (input % 3 === 0) {
return 'Fizz';
}
if (input % 5 === 0) {
return 'Buzz';
}
return input;
};
const output = fizzBuzz();
console.log(output);

Ravikumar
- 2,085
- 12
- 17