Utilizando elementos do primeiro curso criei um código que muda a cor da bolinha a cada click randomicamente.
<!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>Logica III</title>
</head>
<body>
<canvas
style="border-radius: 8px"
id="drawArea"
width="600"
height="400"
></canvas>
<script>
var painting = document.querySelector("#drawArea");
var brushTool = painting.getContext("2d");
brushTool.fillStyle = "lightgrey";
brushTool.fillRect(0, 0, 600, 400);
function showAlert(event) {
var colors = [
"blue",
"red",
"green",
"black",
"violet",
"white",
];
var x = event.pageX - painting.offsetLeft;
var y = event.pageY - painting.offsetTop;
brushTool.fillStyle =
colors[Math.round(Math.random() * colors.length)];
brushTool.beginPath();
brushTool.arc(x, y, 10, 0, 2 * Math.PI);
brushTool.fill();
}
painting.onclick = showAlert;
</script>
</body>
</html>