I make canvas to draw a square with random size , when I press Next button
I call the canvasarea()
function that draws a square with the random size that he get,but I faced a problem with that, because the previous square still in the canvas , and the previous of previous , and so on .
what is the solution?
function canvasarea(){
var canvas = document.getElementById('square');
var context = canvas.getContext('2d');
context.beginPath();
var Size=getSize();
context.rect(10,10, 5*Size, 5*Size);
context.fillStyle = 'red';
context.fill();
context.lineWidth = 1;
context.strokeStyle = 'black';
context.stroke();
}
function getSize(){
var min = 30;
var max = 40;
var size = Math.floor(Math.random() * (max - min + 1) + min)
document.getElementById("sideSize").innerHTML=size;
return size;
}