Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

151
Views
Cannot access 'Agent' before initialization

Hello its my frist time using canvas with this type of code... i don't understand why the error happens, if you could help me know why this is not working... they say the agent could not be found on start of the read... anyway its trying all the time to have a solution . but it expend hours for me to nothing..

const randomRange = (min,max) => {
    return Math.random() * (max - min) + min;
}
//code
var c = document.getElementById("canvastarget");

var width  = c.offsetWidth
var height = c.offsetHeight

var context = c.getContext("2d");

//content

var numberofelements = 40
    const agents = []

    for (let index = 0; index < numberofelements; index++){

        const x = randomRange(0, width)
        const y = randomRange(0, height)

        agents.push(new Agent(x, y))
    }



//classes
class Point {
    constructor(x,y){
        this.x = x
        this.y = y
    }
}

class Agent{

    constructor(x, y) {

        this.pos = new Point(x,y)
        this.radius = 10
        
    }

    draw(context) {
        context.fillStyle = "black"
        
        context.beginPath()
        context.arc(this.pos.x,this.pos.y,this.radius,0,Match.PI * 2);
        context.fill();
    }
}
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <canvas id= canvastarget width = "1080px" height="1080px"></canvas>    
</body>

</html>

The error is not clear for me its my first time doing class!

about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!