I
I
Ingerniated2017-06-05 11:08:33
Canvas
Ingerniated, 2017-06-05 11:08:33

Why is fillRect not a function in the loop?

Good afternoon, tell me why when using cycles it says that fillRect is not a function?
https://jsfiddle.net/f4ocguv4/20/

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Dmitry Luzanov, 2017-06-05
@Ingernirated

Because you overwrote it (wtf?):

if(arr[i][j] == "w") {
  ctx.fillRect = "white"; // чооооо?
} else {ctx.fillRect = "black" // чооооо?}

First write the color to fillStyle and then call fillRect()
ctx.fillStyle = "#FF0000";
ctx.fillRect(20,20,150,100);

Result
Bonus

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question