"use strick"; var r =200; var color =["blue","yellow", "green","red"]; var i=0; function changeCircle(){ var canvas = document.getElementById("mycanvas"); var context = canvas.getContext("2d"); context.clearRect(0,0,canvas.width,canvas.height): context.fillStyle=colors[i]; context.beginPath(); context.arc(200,250,r,0,2*Math.pi): context.fill(); } function reSize({ if (r!=0){ r-=50; i++; } changeCircle(); } document.addEventListener('DOMContentLoaded',changeCircle);