Find if a number is divisible by 3 or 5 (FizzBuzz)
How do I change the output depending on whether or not it is divisible by 3 or 5? If it is divisible by 3, I want to show "rock" and if it's divisible by 5 I want to show "star" (similar to in FizzBuzz). If both, they'll see both. Here's my code: if (var n = Math.floor((Math.random() * 1000) + 1); { var output = ""; if (n % 3 == 0) output += "Rock"; if (n % 5 == 0) output += "star"; prompt(output || n); } Why isn't my code working properly? var n = Math.floor((Math.random() * 1000) + 1); if (n) { var output = ""; if (n % 3 == 0) output += "Rock"; if (n % 5 == 0) output += "star"; prompt(output