<!DOCTYPE html>
<html lang="pt-br">
<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>Programa 3</title>
</head>
<body>
<canvas width="600" height="400"></canvas>
<script>
var canvas = document.querySelector('canvas')
var context = canvas.getContext('2d')
var cores = ['blue','red','green']
var cor = 0
context.fillStyle = 'grey'
context.fillRect(0,0,600,400)
function desenharBolinha(evento){
var x = evento.pageX - canvas.offsetLeft;
var y = evento.pageY - canvas.offsetTop;
context.beginPath()
context.arc(x,y, 10, 0, 2*3.14)
context.fill()
}
function mudarCor(){
if(cor < 3){
context.fillStyle = cores[cor]
cor++
}else{
cor = 0
}
}
canvas.addEventListener('click', desenharBolinha)
canvas.addEventListener("contextmenu", mudarCor)
</script>
</body>
</html>
após vê a solução
<!DOCTYPE html>
<html lang="pt-br">
<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>Programa 3</title>
</head>
<body>
<canvas width="600" height="400"></canvas>
<script>
var canvas = document.querySelector('canvas')
var context = canvas.getContext('2d')
var cores = ['blue','red','green']
var cor = 0
context.fillStyle = 'grey'
context.fillRect(0,0,600,400)
function desenharBolinha(evento){
var x = evento.pageX - canvas.offsetLeft;
var y = evento.pageY - canvas.offsetTop;
context.fillStyle = cores[cor]
context.beginPath()
context.arc(x,y, 10, 0, 2*3.14)
context.fill()
}
function mudarCor(){
cor++
if(cor >= cores.length){
cor = 0
}
return false;
}
canvas.addEventListener('click', desenharBolinha)
canvas.addEventListener("contextmenu", mudarCor)
</script>
</body>
</html>