Reputation: 65
I'm working on a project for school, and I've used a setTimeout() function to execute my flawlessWin function, but it's not executing it. I think I used to right syntax, but I'm new to Javascript, so I may just not see something obvious. Any help or suggestions is appreciated!
I've looked up the syntax to make sure everything is right, and it looks right. I really don't know why it isn't working.
Link to the code - https://codepen.io/Jacob-Bruce/pen/mQgbXa
function executeTimeout() {
setTimeout(flawlessWin, 100);
};
function flawlessWin() {
ctx.font = "30px Arial";
ctx.fillText("Flawless Victory!", canvas.width/3, canvas.height/3)
};
// collision
function collisionDetection() {
for(var c=0; c<brickColumnCount; c++) {
for(var r=0; r<brickRowCount; r++) {
var b = bricks[c][r];
if(b.status == 1) {
if(x > b.x && x < b.x+brickWidth && y > b.y && y <
b.y+brickHeight) {
dy = -dy;
b.status = 0;
score++;
// win condition - find out why the AND log. operator isn't
working
if(score == brickRowCount*brickColumnCount) {
executetimeout();
}
}
}
}
}
}
I expect the flawlessWin function to be executed once the timeout is executed.
Upvotes: 0
Views: 252
Reputation:
Javascript is extremely case sensitive, so when you say
executetimeout();
It should be
executeTimeout();
Upvotes: 0
Reputation: 459
function executeTimeout() {
//setTimeout(flawlessWin, 100);
setTimeout(function () {
flawlessWin();
}, 100);
};
I think you need to use this syntax to use set timeout function,i hope it will work.
Upvotes: 3
Reputation: 2869
You have a typo. Your function is executeTimeout()
, but when you call it inside of
if (score == brickRowCount*brickColumnCount) {
executetimeout();
}
the first "t" in timeout isn't capitalized. JavaScript is case sensitive.
Upvotes: 3