My Javascript code uses 100% of my CPU and doesn't load

I was trying to make a little game with text.
After running the code Game.start() function I lagged and nothing happen.
I think that is the for loop.
Please help me
Here’s my code:

    class unit {
  constructor(health, speed, x, y) {
    this.health = health;
    this.speed = speed;
    this.x = x;
    this.y = y;
  }
  moveTo(xval, yval) {
    this.x = xval;
    this.y = yval;
  }
}

var player = new unit(100, 1, 10, 10);
var unit1 = new unit(50, 1, 1, 12);
var unit2 = new unit(50, 1, 2, 4);
var unit3 = new unit(50, 1, 3, 6);

var i = 0;
var units = 4;
var u = [player, unit1, unit2, unit3];
var k, l, t, r;

function draw(txt) { document.write(txt); };

var Game = {
  width : 20, // Largeur
  height : 20, // Hauteur

  start : function() {
    for(t = 0; t < this.height++; t++) {
    for(k = 0; k < this.width++; k++) {
      for(var x1 = 0; i < units; x1++) {
        if(u[k].x != k) {
          draw('#');
        } else {
          draw('%');
        }
      }
    }
  }
 }
}

Leave a Comment