#Variable Not Displaying In <p>

6 messages · Page 1 of 1 (latest)

stark yacht
#

Why is my variable "angle" not displaying in my <p> id "angle"

#

Variable Not Displaying Variable In <p>

#

Variable Not Displaying In <p>

stark yacht
#

Alright I tweaked the code a bit and im getting closer, I still need help though

#
<!DOCTYPE html>
<html lang="en">
    <head>
        <title></title>
        <meta charset="UTF-8">
        <meta name="viewport" content="width=device-width, initial-scale=1">
        <link href="stylesheet.css" rel="stylesheet">
    </head>
        <p>MousePos: <b><span id="mouse-pos"></span></b></p>
        <p>Angle: <b><span id="angle"></span></b></p>
        <div class="div">
            <img src="compass.png" class="compass-img"></img>
        </div>


    </body>

    <script type="text/javascript">
            const mousePosText = document.getElementById('mouse-pos');
            let mousePos = { x: undefined, y: undefined };
            const angleText = document.getElementById('angle');

            window.addEventListener('mousemove', (event) => {
            mousePos = { x: event.clientX, y: event.clientY };
            mousePosText.textContent = `(${mousePos.x}, ${mousePos.y})`;
            let orgin = { x: 960, y: 520 };

            let X = orgin.x - mousePos.x
            let Y = orgin.y - mousePos.y

            let radian = Math.tan(-1*(X/Y))
            let angle = 360 - (radian*(Math.PI / 180))
            angleText.textContent = angle
            });
        </script>
</html>```
#

The angle variable seems to be a random number between 359.00000000-360.000000000 what is wrong with my math?