如何计算返回函数的长度?

时间:2015-03-25 11:13:34

标签: javascript

for (i=0; i <2; i++) { 
function drinks () { 
    prompt("Please enter how many drinks you had drank.");
    var dNum = return "You had drank" + " " + drinks + "!";
}
}
if (dNum.length === 2) {
console.log("You are the lord of drinks!");
}

我只是Javascript的新手。我所展示的代码有很多语法错误,但我正在为您提供一个更直接的理解示例。希望你知道我的意思;)如果没有,请问。

1 个答案:

答案 0 :(得分:1)

你不需要for循环,

function drinks () { 
   var dNum = prompt("Please enter how many drinks you had drank.");
   return dNum;
}

if (drinks() == 2) {
   alert("You are the lord of drinks!");
}

你是对的,你的代码中有很多错误