I have a JavaScript code that calculates the size of circles on the screen based on multiple variables. Currently, I am repeating the same equation for each circle by numbering all the variables accordingly. Is there a way to simplify this process and run the original variable through the equation without duplicating the code?
The following code shows how I am currently handling this situation:
$( document ).ready(function() {
circle1 = 914;
circle2 = 600;
G1 = circle1/Math.PI;
H1 = Math.sqrt(G1);
J1 = Math.round(H1*20);
J1margin = J1/2;
$('.circle1').animate({"height":J1, "margin-top":"-"+J1margin, "width":J1, "margin-left":"-"+J1margin});
G2 = circle2/Math.PI;
H2 = Math.sqrt(G2);
J2 = Math.round(H2*20);
J2margin = J2/2;
$('.circle2').animate({"height":J2, "margin-top":"-"+J2margin, "width":J2, "margin-left":"-"+J2margin});
});// JavaScript Document
I believe there must be a simpler solution to avoid repetition in the code, but I haven't been able to find one online. Any help or suggestions would be greatly appreciated. Thank you!