Help with a code to calculate distance between 2 coordinates using Latitude and Longitude.

Here is the Finished code that worked, thanks to the help from @J. D. and @yisrael-wix

function distance ( lat1 , lat2 , lon1 , lon2 )
{
lon1 = lon1 * Math . PI / 180 ;
lon2 = lon2 * Math . PI / 180 ;
lat1 = lat1 * Math . PI / 180 ;
lat2 = lat2 * Math . PI / 180 ;

    **let**  dlon  =  lon2  -  lon1 ; 
    **let**  dlat  =  lat2  -  lat1 ; 
    **let**  a  =  Math . pow ( Math . sin ( dlat  /  2 ),  2 )  
            +  Math . cos ( lat1 ) *  Math . cos ( lat2 )  
            *  Math . pow ( Math . sin ( dlon / 2 ), 2 ); 
           
    **let**  c  =  2  *  Math . asin ( Math . sqrt ( a )); 

    **let**  r  =  3956 ; 

    **return** ( c  *  r ); 

} 

$w ( ‘#userDataset’ ). onReady (() => {
const lat1 = Number ( $w ( “#userLat” ). text )
const lat2 = Number ( $w ( “#profileLat” ). text )
const lon1 = Number ( $w ( “#userLong” ). text )
const lon2 = Number ( $w ( “#profilelong” ). text )
$w ( “#distanceMiles” ). text = Math.round ( distance ( lat1 , lat2 , lon1 , lon2 )) + " Miles"
})