<!DOCTYPE html>
<html>
<head>
<title> This is a test file</title>
</head>
<body>
<script>
function factorial(x)
{
if(x<10) throw new Error("x must not biger than 10");
for (var f=1; x<10; f*=x , x++)
return f;
}
factorial(2);
</script>
</body>
</html>
报错原因是,你的代码要求的 throw new Error
可以用 alert。
function factorial(x)//求阶乘对了。我使用F12在Google Chrome里面看到报错信息了。这个为什么不显示出来啊?一般我们在网页上点点点,报错的话会自己弹出报错窗口的。我还以为这个throw的句法会实现这种功能呢。
本回答被提问者采纳