Javascript 函数控制台日志

时间:2021-01-15 19:14:12

标签: javascript

我正在尝试 log "test" inside a console 但它不起作用。我该如何解决这个问题?

我已经尝试将函数放在 draw() function 中,但它没有按预期工作。

let space = [0, 0, 0, 0, 0, 0, 0, 0, 0];
let x, y, s;

function setup() {
  createCanvas(500, 500);
  a = game;
}

function draw() {
  background(200);
  fill(0);
  text('X:' + mouseX, 10, 10);
  text('Y:' + mouseY, 10, 20);


  //grid
  x = 100;
  y = 100;
  s = 100;

  fill(200, 0, 0, 0);

  rect(x, y, 300);

  rect(x, y, s);
  rect(x + 100, y, s);
  rect(x + 200, y, s);

  rect(x, y + 100, s);
  rect(x + 100, y + 100, s);
  rect(x + 200, y + 100, s);

  rect(x, y + 200, s);
  rect(x + 100, y + 200, s);
  rect(x + 200, y + 200, s);
  game();
}

function game() {
  if ((mouseX < x) && (mouseX > x + 100) && (mouseY < y) && (mouseY > y + 100)) {
    console.log('test');
  }
}

0 个答案:

没有答案