由于某种原因,以下代码不起作用。
var a1 = Math.floor(Math.random()*4+1);
//Answer2
for(a2 = 0; a2 != a1 && a2 != 0; a2 = Math.floor(Math.random()*4+1)){
alert(a2);
}
Run Code Online (Sandbox Code Playgroud)
我试图让“a2”成为 1-4 的整数,但不等同于“a1”。
怎么了?提前致谢!!!
编辑:
谢谢大家的帮助!这是我的最终结果:
var a1, a2;
a1 = Math.floor(Math.random()*4+1);
a2 = a1;
while(a2 == a1){
a2 = Math.floor(Math.random() * 3 + 1);
alert(a2);
}
Run Code Online (Sandbox Code Playgroud) 这是我第一次从头开始制作迷你游戏.
谷歌浏览器在运行时给我这些错误:
Uncaught TypeError: Cannot call method 'draw' of undefined Logic.js:28
loop Logic.js:28
startLoop Logic.js:35
init Logic.js:19
Run Code Online (Sandbox Code Playgroud)
当我使用"setInterval"时它工作正常,但我想要最新的东西.我不认为requestAnimationFrame与它有任何关系.
但我没有看到什么是错的!请帮忙.
// Create the canvas
var canvas = document.getElementById("canvas");
var ctx = canvas.getContext("2d");
canvas.addEventListener('click', canvasClick, false);
//Declarations
var isPlaying = false;
var animeFrame = window.requestAnimationFrame ||
window.webkitRequestAnimationFrame ||
window.mozRequestAnimationFrame ||
window.msRequestAnimationFrame ||
window.oRequestAnimationFrame;
var Pair1;
var Pair2;
//init
function init(){
startLoop();
Pair1 = new Pair();
Pair2 = new Pair();
alert('init called');
}
//Draw
function loop(){
if(isPlaying){
Pair1.draw();
Pair2.draw();
animeFrame(loop);
}
}
function …Run Code Online (Sandbox Code Playgroud)