I am trying to calculate and display the circumference by retrieving the already defined radius from the given code of a drawn circle. Is it the way I typed out the formula wrong or does it need to be in the same script section?
function draw() {
var canvas = document.getElementById('circle');
if (canvas.getContext) {
var ctx = canvas.getContext('2d');
var X = canvas.width / 2;
var Y = canvas.height / 2;
var R = 45;
ctx.beginPath();
ctx.arc(X, Y, R, 0, 2 * Math.PI, false);
ctx.lineWidth = 3;
ctx.strokeStyle = '#FF0000';
ctx.stroke();
}
}
function calculatecircumference() {
var circumference = ((2) * (Math.Pi) * (R));
}
document.getElementById("Circumference").innerHTML = circumference;
<!Doctype>
<html>
<body onload="draw();">
<canvas id="circle" width="150" height="150"></canvas>
</body>
<p>Circumference: <span id="Circumference"></span></p>
</html>