简体   繁体   中英

How do I calculate the length of return function?

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!");
}

I'm just a newbie for Javascript. The code I've shown has many syntax errors, But I'm making an example for you to understand more directly. Hope you know what I meant ;) If not, Please ask.

You dont need the for-loop,

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!");
}

You're right, you have a lot of errors in your code

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM