当满足给定条件时,我找不到推荐的方法来停止函数。我应该使用像exit
或break
这样的东西吗?
我目前正在使用这个:
if ( x >= 10 ) { return; }
// other conditions;
尝试使用return语句。它工作得最好。在满足条件时停止该功能
`function anything() { var get = document.getElementsByClassName("text ").value; if (get == null) { alert("Please put in your name"); }
return;
var random = Math.floor(Math.random() * 100) + 1;
console.log(random);
}`