Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

99
Visualizações
Uncaught SyntaxError: Unexpected strict mode reserved word

I have been searching for a while now on what this error means (error: Uncaught SyntaxError: Unexpected strict mode reserved word), or how to fix it but I just cannot find anything, so I was hoping that someone here could help? By the way going to bed on this so only gonna read responses (if any) tomorrow.

Here is the line giving me the error:

for (let i = 0; i < 10; i++) { //(And then the code)

FOR PEOPLE WHO NEED CONTEXT:

const canvas = document.getElementById('canvas1');

const ctx = canvas.getContext('2d');

class background {
  draw(){   
    ctx.fillstyle = 'green';
    ctx.beginPath();
    ctx.fillRect(0,10,800,500);
    ctx.fill();
    ctx.closePath;
  };
};

const Backdrop = new background();

Backdrop.draw();

class artist {
  for (let i = 0; i < 10; i++) {
    draw(){
      ctx.fillStyle = 'lime';
      ctx.beginPath();
      ctx.fillRect(0+i,10,20,15);
      ctx.fill();
      ctx.closePath;
    };
  };
};

const box = new artist();

box.draw();

Ok send help, thanks!!

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

As @Barmar commented you can use the for loop inside your draw().

Here is a working example:

const canvas = document.getElementById('c')
canvas.style.background = 'black'
const ctx = canvas.getContext('2d')

class artist {
  draw() {
    ctx.fillStyle = 'lime'
    
    for (let i = 0; i < 10; i++) {
      ctx.fillRect(10 + i * 30, 30, 20, 15)
    }
    
  }
}

const box = new artist()
box.draw()
<canvas width="400px" height="170px" id="c"></canvas>

about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda