This is my entire script. it is for the find my hat project. but the point is that (node.content === ‘o’ && node .content === ‘o’) is true and yet the setTimeout is not being called.
const prompt = require(‘prompt-sync’)({sigint: true});
const goalY = 4;
const goalX = 4;
let posY = 5;
let posX = 0;
class Node {
xpos;
ypos;
content;
}
let grid = ;
const gridSize = 10;
const gridContent = [
‘’,‘’,‘’,‘’,‘’,‘’,‘’,‘’,‘’,‘’,
‘’,‘’,‘’,‘’,‘’,‘’,‘’,‘’,‘’,‘’,
‘’,‘’,‘’,‘’,‘’,‘’,‘’,‘’,‘’,‘’,
‘’,‘’,‘’,‘’,‘’,‘’,‘o’,‘’,‘’,‘’,
‘’,‘’,‘’,‘’,‘’,‘’,‘’,‘’,‘’,‘’,
‘’,‘’,‘’,‘o’,‘’,‘’,‘’,‘’,‘’,‘’,
‘’,‘’,‘’,‘’,‘’,‘’,‘’,‘’,‘’,‘’,
‘’,‘’,‘’,‘’,‘’,‘’,‘’,‘’,‘’,‘’,
‘’,‘’,‘’,‘’,‘’,‘’,‘’,‘’,‘>’,‘’,
‘’,‘’,‘’,‘’,‘’,‘’,‘’,‘’,‘’,‘’
]
function updateGrid(){
for(let y = 0; y < gridSize; y++){
for(let x = 0; x < gridSize; x++){
if(x === 0 && y === 0){
grid = [];
}
let node = new Node;
node.xpos = x;
node.ypos = y;
grid.push(node);
node.content = gridContent[x*y];
if(node.content === ''){
node.content = '+';
}
if(posY === y && posX === x){
if(node.content === 'o' && node.content === 'o'){
setTimeout(() => {
console.log('Game lost');
}, 1000);
console.log('test');
}
node.content = '*';
}
if(x === 0){
process.stdout.write('\n');
}
process.stdout.write(node.content);
}
}
}
function getInput(){
let input = null;
input = prompt('Input: ');
if(input === 's'){
posY ++;
updateGrid();
getInput();
}
if(input === 'w'){
posY --;
updateGrid();
getInput();
}
if(input === 'd'){
posX ++;
updateGrid();
getInput();
}
if(input === 'a'){
posX --;
updateGrid();
getInput();
}
}
updateGrid();
getInput();