请问如何解决这个AS3功能?
谢谢
function dispari(numero:int):Boolean;
{
//check if the number is odd or even
if (numero % 2 == 0)
{
returns false;
}
else
{
returns true;
}
}
Run Code Online (Sandbox Code Playgroud)
错误:1071:语法错误:在属性返回后期望定义关键字(例如函数),而不是false.
为什么(;)在函数语句的末尾有一个分号?我没有做任何 AS3编码,但它看起来不正确,粗略地浏览网上的一些样本没有它.
我怀疑这可能是导致你的问题的原因.试试这个:
function dispari(numero:int):Boolean
{
//check if the number is odd or even
if (numero % 2 == 0)
{
return false;
}
else
{
return true;
}
}
Run Code Online (Sandbox Code Playgroud)
我也改变了return语句以匹配AS3的其他部分返回值(谢谢,@ Herms,忘了提到:-)
Pax在答案中是正确的,但您可以通过返回结果来简化它:
function dispari(numero:int):Boolean
{
return (numero % 2 != 0);
}
Run Code Online (Sandbox Code Playgroud)