I can create the random circle fine, but I want the circle to be created and when the circle is clicked, the score to be increased and a new circle is made.
I have already tried using an addEventListener
but that doesn't work as it throws an error, I have also tried using a circle.onclick = function() {blah}
but that doesn't do anything at all, not even throws an error.
var canvas = document.getElementById("cnv")
var context = canvas.getContext("2d");
document.getElementById("startGame").addEventListener("click", function() {
createGameCircle();
});
function createGameCircle() {
radius = 20;
context.clearRect(0, 0, canvas.width, canvas.height);
var circle = [
context.beginPath(),
rand_x = Math.random(1) * max,
rand_y = Math.random(1) * max,
context.arc(rand_x, rand_y, radius, 0, 2 * Math.PI),
context.fill(),
context.closePath()
];
circle;
circle.onclick = function() {
score++;
document.getElementById("score").innerHTML = (score);
createGameCircle();
}
}
So with this code, when the circle is clicked I expected a new one to be made again randomly, and a score to be added on. But nothing happens at all, as well no errors are thrown.