I am making a weird block movement thing, but after it moved 10 times it says:
Uncaught RangeError: Maximum call stack size exceeded
And my purpose is to let it move the whole time, here is the code BTW:
<html>
<head>
<title>Look - The game</title>
</head>
<body>
<div id="square" style="position:absolute; width:5px; height:5px; background:black"></div>
<script src="http://code.jquery.com/jquery-2.1.1.min.js"></script>
<script>
var square = document.getElementById("square");
var duration = 1000;
var steps = 1;
function movesquare(){
var randomtop = Math.floor(Math.random() * screen.height);
var randomleft = Math.floor(Math.random() * screen.width);
$(square).animate({marginTop:randomtop, marginLeft:randomleft}, duration, movesquare);
duration -= steps;
steps = steps * 2;
}
movesquare();
</script>
</body>
Maximum call stack size exceededindicates that you have an a kind of endless loop and if the browser would not stop your script, your browser most likely will become unresponsive in such a situation.durationis less than or equal to zero. So long as it's greater than zero, there'll be no recursion.