Why my program not working properly.. please help me

My code is here.

const prompt = require(‘prompt-sync’)({sigint: true});

const hat = ‘^’;

const hole = ‘O’;

const fieldCharacter = ‘░’;

const pathCharacter = ‘*’;

let currentPlaying=true;

class Field {

constructor(field){

this._field=field;

this.x=0;

this.y=0;

this._field[0][0]=pathCharacter;

}

get field(){

return this._field;

}

print(){

const displayStr=this._field.map(row=>row.join('')).join('\n');

console.log(displayStr);

}

askQuestion(){

let question=prompt('Which direction you want to move').toUpperCase();

switch(question){

  case 'U':

  console.log('Move Up');

  this.y -=1;

  break;



case 'D':

  console.log('Move Down');

  this.y +=1;

  break;



case 'L':

  console.log('Move Left');

  this.x -=1;

  break;



case 'R':

  console.log('Move Right');

  this.x +=1;

  break;

  default:

  console.log('Move U, D, L or R');

  this.askQuestion();

  break;

}

}

static generateField(height, width, percentage=0.1){

const field= new Array(height).fill(0).map(el=>new Array(width));

for(let i=0;i<height;i++){

  for(let j=0; j< width; j++){

    const prod= Math.random();

    field[j][i]=prod>percentage?fieldCharacter: hole;

  }

}

//set the hat location

const hatLocation={

  x: Math.floor(Math.random()*width),

  y: Math.floor(Math.random()*height)

};

//make sure that hat is not at start

while(hatLocation.x===0 && hatLocation.y===0)

{

  hatLocation.x=Math.floor(Math.random()*width);

  hatLocation.y=Math.floor(Math.random()*height);

}

field[hatLocation.y][hatLocation.x]=hat;

return field;

}

playGame(){

while(currentPlaying){

  this.print();

  this.askQuestion();

  if(!this.inBounds){

  console.log('You are out of bounds');                currentPlaying=false;

  break;

    

  }

   else if(this.isHole){

  console.log('You are fall in a hole.');       currentPlaying=false;

  break;

    

  }

   else if(this.isHat){

  console.log('Congratulations!!! You have found the hat.');       

  currentPlaying=false;

  break;

    

  }

  this.field[this.x][this.y]=pathCharacter;

}

}

inBounds(){

return(

  this.y>=0 && this.x>=0 && this.y < this.field.length && this.x < this.field[0].length

);

}

isHat(){

return this.field[this.y][this.x]=== hat;

}

isHole(){

return this.field[this.y][this.x]=== hole;

}

}

const myfield = new Field(Field.generateField(10, 10, 0.2));

function game(){

while(currentPlaying){

myfield.playGame();

}

console.log(‘Game Over!’);

}

game();

Hi! Welcome to the forums :slight_smile:

Please see this note about formatting code: [How to] Format code in posts as it’s very tough to read a lot of unformatted code (let alone debug).

Also, try to give a constructive opinion as to what you might think the problem is, and maybe some context as to what change made it not work.

ok thank you. I solved this problem @ toastedpitabread