所以,这就是我所拥有的(我正在运行JQuery):
http://jsfiddle.net/KDmwn/111/
The computer chose <span id="x"></span>.
$(document).ready(function () {
var x = function getRandomInt(1, 4) {
return Math.floor(Math.random() * (4 - 1 + 1)) + 1
};
$('#x').html(x);
}
我觉得问题与此$('#x').html(x);
非常感谢任何帮助。谢谢!
答案 0 :(得分:4)
问题是因为你的x
函数有两个整数设置为参数,这在语法上是不正确的。
要实现所需,您应该删除参数列表中的整数,修复DOMReady处理程序末尾的不匹配括号,还可以从- 1 + 1
值中删除Math.random
试试这个:
var x = function getRandomInt() {
return Math.floor(Math.random() * 4) + 1;
}
$('#x').html(x);
答案 1 :(得分:0)