Skip to main content

Displaying red square with JS [closed]

I'm trying to display this red square on the screen with JS. Any idea where I'm going wrong? Here is my code :

const canvas = document.querySelector('canvas')
const c = canvas.getContext('2d')

canvas.width = innerWidth
canvas.height = innerHeight

class Player {
    constructor() {
        this.position = {
            x: 200,
            y: 200
        }

        this.velocity = {
            x: 0,
            y: 0
        }
        // this.image = 
            this.width = 100
            this.height = 100
    }
    draw() {
        c.fillStyle = 'red'
        c.fillRect(this.position.x, this.position.y, this.position.width, this.position.height)
    }
}

const player = new Player()
player.draw()

No idea where I'm going wrong here. I should be seeing a red square

Via Active questions tagged javascript - Stack Overflow https://ift.tt/fDqtxLw

Comments