Find if a number is divisible by 3 or 5 (FizzBuzz)

梦想的初衷 提交于 2019-12-05 21:53:33

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 || n);
}

The var inside the if statement is a syntax error. My browser shows this error:

SyntaxError: expected expression, got keyword 'var'

So I think you should declare variable n before telling the if statement that var n is your comparison expression.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!