Inconsistent Object/Mesh Rotations in ThreeJS

I am encountering rotation issues in THREEJS where my object (From blender, gltf.scene) totations are extremely unpredictable and inconsistent. I want my object to spin like a ballerina when the mouse moves (depending on the x coordinates of the mouse, the object will spin: anticlockwise when the mouse moves to the right and clockwise when the mouse moves to the left).

There are two points in my code where I rotated my object 1) initially when I imported my model and 2) in the tick function (so it moves like a ballerina accordingly to the position of the mouse).

This is the main part of my issue: Sometimes when I load my page it does exactly what I want. However, sometimes when I reload the page the object might not even rotate, and I can reload the page and my object will be fine again. I searched online for similar issues already and I believe it is due to Gimbal Lock. I am unsure how to fix my code so my rotations are not inconsistent. I also have a imageMesh object created in THREEJS that will spin in the same manner as my object imported from blender and this object never has the rotation issue present in gltf.scene object.

Code From Initially Loading The Object

// Load GLTF Model
    gltfLoader.load(
        '/Trial8.glb',
        (gltf) => {
            modelRef.current = gltf.scene;
            gltf.scene.traverse((child) => {
                if (child.isMesh) {
                    child.geometry.center(); // Centers the geometry relative to its local origin
                    child.material = bakedMaterial;
                    child.castShadow = true;
                    console.log('Model material:', child.material.constructor.name);
                }
            });
            gltf.scene.position.set(1.5, -7.54, 3);

            // Set initial rotation using Quaternion to avoid Euler issues
            const initialQuaternion = new THREE.Quaternion();
            initialQuaternion.setFromEuler(new THREE.Euler(0, -Math.PI / 2, Math.PI / 2, 'XYZ'));
            gltf.scene.quaternion.copy(initialQuaternion);
            gltf.scene.scale.set(0.5, 0.5, 0.5);
            scene.add(gltf.scene);

            // Add AxesHelper to visualize origin
            const axesHelper = new THREE.AxesHelper(1); // 1 unit long, scaled with model (0.5)
            gltf.scene.add(axesHelper);
            

            const originMarker = new THREE.Mesh(
                new THREE.SphereGeometry(0.1),
                new THREE.MeshBasicMaterial({ color: 0xff0000 })
            );
            originMarker.position.set(0, 0, 0);
            modelRef.current.add(originMarker);
        },
        (progress) => {
            console.log(`Loading: ${(progress.loaded / progress.total * 100).toFixed(2)}%`);
        },
        (error) => {
            console.error('Error loading GLTF:', error);
        }
    );

Code in Tick Function

// Animation loop
    const clock = new THREE.Clock();
    const tick = () => {
        const elapsedTime = clock.getElapsedTime();

        if (cameraRef.current) {
            const targetX = mouse.x * moveRange;
            const targetZ = -mouse.y;
            cameraRef.current.position.x = THREE.MathUtils.lerp(
                cameraRef.current.position.x,
                targetX,
                dampingFactor
            );
            cameraRef.current.position.z = THREE.MathUtils.lerp(
                cameraRef.current.position.z,
                targetZ,
                dampingFactor
            );
            cameraRef.current.lookAt(
                cameraRef.current.position.x,
                0,
                cameraRef.current.position.z
            );
        }

        // Add rotation for models based on mouse X
        const targetRotationZ = mouse.x * Math.PI; // Adjust rotation range as needed
        if (modelRef.current) {
            // Define target rotation based on mouse.x
            const targetRotationZ = mouse.x * Math.PI; // Same rotation range as before
            const targetQuaternion = new THREE.Quaternion();
            // Combine initial rotation with mouse-driven Y-axis rotation
            targetQuaternion.setFromEuler(
                new THREE.Euler(0, -Math.PI / 2 + targetRotationZ, Math.PI / 2, 'XYZ')
            );
            // Interpolate current quaternion to target quaternion
            modelRef.current.quaternion.slerp(targetQuaternion, dampingFactor);
        }
        imageMesh.rotation.z = THREE.MathUtils.lerp(
            imageMesh.rotation.z,
            targetRotationZ,
            dampingFactor
        );

        // Update directional light's x-position based on mouse.x
        const lightTargetX = initialLightX + mouse.x * lightMoveRange;
        directionalLight.position.x = THREE.MathUtils.lerp(
            directionalLight.position.x,
            lightTargetX,
            dampingFactor
        );

        renderer.render(scene, camera);
        requestAnimationFrame(tick);
    };
    tick();

What is the difference between ‘const dotenv = require(‘dotenv’);’ and ‘require(‘dotenv’).config();’ in Node.js?

I’m learning how to use the dotenv package in my Node.js project to manage environment variables. I’ve seen two common ways to include it in the code:

const dotenv = require('dotenv');

and

require('dotenv').config();

What exactly is the difference between these two statements? Are they both importing the module? Do they both load the environment variables from the .env file? When should I use one over the other?

And should I use dotenv.load(); in both after exporting the module? Or what is the usage of this method?

Also, does either of these export anything, or are they just importing the module? I want to understand the best practice to use dotenv in my application.

What AI tool can actually write code for me in May 2025 [closed]

TL;DR: What AI tool(s) can actually write code (i.e. not just code complete or assist) for an experienced, but not professional (i.e. hobbyist) developer working on an online game in late May 2025, who has an existing codebase but has never used AI?

I’m posting this question on Sunday, 25th May 2025. The date is important because the industry is moving so fast that if I link to any research I’ve done I think it will be out of date by the time I review any answers!

For some context, I’m an indie dev who has written the codebase for a multi-player online real time strategy game (MMORTS) myself. I’m self-taught, and not a “professional” dev. I have in the past used freelance developers to help me, some sourced from this very site, other times using freelancer.com, and one great dev in India who I use to do the time-consuming, fiddly stuff I just don’t have time to do. In these scenarios, I architect the solution and tell them what I need done. I’ve almost never handed over the reigns to someone and said “develop this feature” or “make this script run faster” or “fix this bug” without me knowing the optimal solution to begin with.

The game has been in development for a few years, and has a small player base. I would still call it “early alpha” because I’m not confident enough to put it out there until I’m satisfied with the content, replayability and stability of the game.

I use the LAMP stack and have no intention of changing this – it’s what I know and my game runs well using it. It’s hosted on a VPS with a small amount of CPU, RAM etc. I use raw HTML5/CSS3/JS on the front end, with PHP 8.3 and MariaDB 10.11.13 on the back end.

My codebase is about 100k LoC, and there are less than 10 front-end files with ~60 PHP scripts. I use very few libraries included as files (a CSS animation library, marker clusterer library and two geometry libraries, turf.js on the front-end and GeoPHP on the back end) and only one real-time API (google maps JavaScript version).

Now here’s my problem: I’ve never used any AI at all. However, I want to use it to work through my backlog and just develop faster. I’d like to start with minor features and bug fixing. If it works well, I’d move on to major features and code optimisation.

I am happy to pay a small amount per month on a subscription basis that I can cancel if it doesn’t meet my needs, but I would prefer to stick to one tool if possible.

As an additional question: I am happy to supply the tool with my entire codebase (*.html, *.css, *.js, *.php files), but how would any tool read my database? Do I just export the schema as an *.sql file? Or the actual data as well (which is massive)?

method getElementsByClassName issue

Facing a problem in moving the card
im use this function to scroll the card item by two button next and prev
it work with me but when i duplicate card item under the first one it does not work with the second card list ,can any one help me
how can i use this function with many card list
here is my full code

let left_btn=document.getElementsByClassName('bi-chevron-left')[0];
let right_btn=document.getElementsByClassName('bi-chevron-right')[0];
let cards=document.getElementsByClassName('cards')[0];




left_btn.addEventListener('click',()=>{

    cards.scrollLeft -=140;
})

right_btn.addEventListener('click',()=>{

    cards.scrollLeft +=140;
})
section{


    position: relative;
    width: 100%;
    height: auto;
    padding: 0px 30px;
    bottom: 10px;
    color: white;
    margin-bottom: 40px;
    
    
}

section .movie-list-title{

    
    margin-top: 10px;
}

section .cards{


   position: relative;
   
   width: 100%;
   height: 350px;
   /* border: 1px solid white; */
   
   display: flex;
   align-items: center;
   overflow-x: auto;
   scroll-behavior:smooth ;

   

}

section .cards .card{


    position: relative;
    min-width: 200px;
    height: 280px;
    /* border: 1px solid white; */
    border-radius: 10px;
    margin-right: 30px;
    background: transparent;
    transition: .3s linear ;
     

 }

section .bi-chevron-left , .bi-chevron-right{

    position: absolute;
    top: 50%;
    left: 3%;
    width: 25px;
    height: 25px;
    background: gray;
    color: white;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    font-size: 12px;
    cursor: pointer;
    transition: .3s linear;
    z-index: 999999999;
    opacity: 0;
    
}


section .bi-chevron-right{

   left: unset;
   right: 3%;
}

section:hover .bi-chevron-left{

    opacity: 1;
 }

 section:hover .bi-chevron-right{

    opacity: 1;
 }

section .cards::-webkit-scrollbar{


    display: none;
 }



 section .cards .card:hover .poster{

    transform: scale(1.1);
  
    

   }



 section .cards .card .poster{


  width: 100%;
  height: 100%;
  border-radius: 12px;
  position: relative;
  transition: all .5s ease-in-out;
  /* margin-left: 20px; */

 }
<?php
session_start();
?>

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <link
        href="https://fonts.googleapis.com/css2?family=Roboto:wght@100;300;400;500;700;900&family=Sen:wght@400;700;800&display=swap"
        rel="stylesheet">
        <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.7.2/css/all.min.css">
        <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/[email protected]/font/bootstrap-icons.min.css">
       
        
     
    
    <link rel="stylesheet" href="styleee.css">

   
    <title> onc</title>
</head>
<body>


<?php

include 'signUp.php';
include 'login.php';

?>

   <div class="navbar">
        <div class="navbar-container">
             <div class="logo-container"><h1 class="logo">ONC</h1></div>   
             <div class="menu-container">
                <ul class="menu-list">

                   
                    <li class="menu-list-item">Home</li>
                    <li class="menu-list-item">Movies</li>
                    <li class="menu-list-item">series</li>
                    <li class="menu-list-item">popular</li>
                    <li class="menu-list-item">trends</li>
                    
                    
                </ul>
             </div> 
             
           
             <div class="profile-container">
                <!-- <img class="profile-picture" src="img/profile.jpg" alt=""> -->
                 
                <div class="profile-text-container">

                  <a class="btnLogin-popup"> Login</a>
                  
                </div>

                <div class="toggle">

                    <i class="fa-solid fa-moon toggle-icon"></i>
                    <i class="fa-solid fa-sun toggle-icon"></i>
                     <div class="toggle-ball"></div>
                </div>
             </div>  
        </div>
   </div>

   


   
   


   <div class="container">    <!--start div container -->

     <div class="content-container">  <!--start div content-container --> 

        <div class="featurd-content">
                
        </div>
 

         <div class="movie-list-container">  <!--start div movie-list-container1 --> 

           <section>

         <h1> Watch Today</h1>
         <i class="bi bi-chevron-left"></i>
         <i class="bi bi-chevron-right"></i>
         
         <div class="cards">

           <?php
            $servername = "localhost";
            $username = "root";
            $password = "";
            $dbname = "login_register";

            // Create connection
            $conn = new mysqli($servername, $username, $password, $dbname);
            // Check connection
            if ($conn->connect_error) {
              die("Connection failed: " . $conn->connect_error);
            }
            $sql = 'SELECT * FROM movies ';
            $result = $conn->query($sql);

            
            if ($result->num_rows > 0) {
              // output data of each row
              while ($row = $result->fetch_assoc()) {

                
                
           ?>
           
            <a href="#" class="card">
            <img src="../image/<?php echo $row['movie_image']; ?>" alt="" class="poster">
            </a>

            <?php }
            } ?>
        
         </div>
         
         </section>

         </div>  <!--end div movie-list-container1 --> 





         <div class="movie-list-container">  <!--start div movie-list-container2 --> 

         <section>

            <h1> Movies Today</h1>
           <i class="bi bi-chevron-left"></i>
         <i class="bi bi-chevron-right"></i>
         

         
         
         <div class="cards">

           <?php
            $servername = "localhost";
            $username = "root";
            $password = "";
            $dbname = "login_register";

            // Create connection
            $conn = new mysqli($servername, $username, $password, $dbname);
            // Check connection
            if ($conn->connect_error) {
              die("Connection failed: " . $conn->connect_error);
            }
            $sql = 'SELECT * FROM movies ';
            $result = $conn->query($sql);

            
            if ($result->num_rows > 0) {
              // output data of each row
              while ($row = $result->fetch_assoc()) {

                
                
           ?>
           

            <a href="#" class="card">
            <img src="../image/<?php echo $row['movie_image']; ?>" alt="" class="poster">
            </a>

            <?php }
            } ?>
        
         </div>


            </section>


            
            

            </div>  <!--end div movie-list-container2 --> 



            

            

         </div>     <!--end div content-container -->         

         </div>  <!--end div container -->

How to deallocate WASM heap memory that is exported to Javascript

I was trying to find a way to export vector or other heap alocated data to Javascript. I tried this:

use wasm_bindgen::prelude::*;
use std::alloc::{Layout, dealloc};

#[wasm_bindgen]
pub struct ArrayBuffer {
    ptr: *const u8,
    len: usize,
}

#[wasm_bindgen]
impl ArrayBuffer {
    #[wasm_bindgen(getter)]
    pub fn ptr(&self) -> *const u8 {
        self.ptr
    }

    #[wasm_bindgen(getter)]
    pub fn len(&self) -> usize {
        self.len
    }
}

#[wasm_bindgen]
pub fn get_array() -> ArrayBuffer {
    let data = vec![1, 2, 3, 4, 5];
    let ptr = data.as_ptr();
    let len = data.len();

    std::mem::forget(data);

    ArrayBuffer { ptr, len }
}

#[wasm_bindgen]
pub fn free_array_raw(ptr: *mut u8, len: usize) {
    unsafe {
        let mut v = Vec::from_raw_parts(ptr, len, len);
        v.fill(0); 
        drop(v);  
    }
}

The I compile with wasm-pack targetting nodejs

wasm-pack build --target nodejs

Here is my Javascript code I used to test it

const wasm = require('./pkg/wasm.js');

async function run() {
  const arrayBuffer = wasm.get_array();
  const ptr = arrayBuffer.ptr;
  const len = arrayBuffer.len;

  const memory = wasm.__wasm.memory;

  const uint8Array = new Uint8Array(memory.buffer, ptr, len);

  console.log(uint8Array);

  arrayBuffer.free();
  wasm.free_array_raw(ptr, len);
  
  console.log(uint8Array);
}

run().catch(console.error);

The memory does not get deallocated, I still can access the data

[root@localhost wasm]# node ./main.js
Uint8Array(5) [ 1, 2, 3, 4, 5 ]
Uint8Array(5) [ 1, 2, 3, 4, 5 ]

How is the correct way to deallocate the heap memory?

Parsing text in html document and replacing symbols with open and close html tags

I am trying to parse through an HTML document text and replace certain symbols (### and **) with HTML tags. I’m not sure how to implement open and close tags like <ul><li></li></ul> and <b></b>.

For example:

  • ### should be a bullet.
  • **Requirement Analysis and Planning** should be <b>Requirement Analysis and Planning</b>

Currently using jQuery. Please advise!

  $(document).ready(function() {

    //var balle = '<i class="fas fa-square"></i>';
    var balle = '<ul><li></li></ul>'; //BULLET
    var bold = '<b></b>'; //BOLD TEXT

    $(".chat-box").children().each(function() {
      $(this).html($(this).html().replace(/###/g, balle));
    });

  }); //END JQUERY 
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.7.1/jquery.min.js"></script>
<div class="chat-box">
  <div>
    <pre><code>Implementing and managing an orchestration tool involves several key steps and considerations to ensure that it effectively automates and coordinates various tasks and workflows within an IT environment. Here’s a detailed description of the experience:<br>
<br>
### 1. **Requirement Analysis and Planning**<br>
   - **Understanding Needs:** Begin by understanding the specific needs of your organization. Identify the tasks and workflows that need to be automated.<br>
   - **Tool Selection:** Choose an orchestration tool that fits your requirements. Popular options include Ansible, Puppet, Chef, Kubernetes, and Terraform.<br>
   - **Resource Allocation:** Allocate the necessary resources, including personnel, budget, and infrastructure.<br>
<br>
### 2. **Setup and Configuration**<br>
   - **Installation:** Install the chosen orchestration tool on the appropriate servers or environments.<br>
   - **Configuration:** Configure the tool according to your organization's policies and requirements. This may include setting up authentication, permissions, and network configurations.<br>
   - **Integration:** Integrate the orchestration tool with existing systems, such as CI/CD pipelines, monitoring tools, and cloud services.<br>
<br>
</code></pre>
  </div>
</div>

How can I capture user activity e.g. click , type on a variaty of elements?

I need to track user interactions on a web application. This includes clicks on input fields, buttons, hyperlinks, radio buttons, checkboxes, and similar elements.

For example, if there’s an input field with a label like “Username,” I want to log actions like:

  • User clicked on Username
  • User typed ‘dj2500’ in Username”

The logging should be in plain text and easy to read.The code should be generic, meaning it should work across different web applications without needing specific adjustments for each one.

I have tried to use event listener present in the JS. When clicked on the dropdown or the checkbox , radio button it does seem to be generic . Can anyone help me if a library exist in npm .

HTML div element not honoring visibility nor style attributes as they are updated

I’m creating basically a tooltip for SVG groups. I’m not using the title=>tooltip built in because I want to have richer content eventually that plain text can’t support.

I’ve used a div element to render the text. My intention was for the div to be visible when the group is hovered and hidden when no group has focus. Also for the div to move to proximity to the group.

While the innerHTML is updated, the visibility and position are not.

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <style>
svg {
    max-width: 100%;
    height: auto;
    display: block;
    g {
        transform-origin: 50% 50%;
        path {
            fill: #ccc;
            transition: background-color 200ms ease-in;
            &:hover {fill: #c00;}
            }
        &:hover {cursor: pointer;}
        }
    }
#popup {
    position: absolute;
    background-color: white;
    border: 1px solid #ccc;
    padding: 10px;
    font-size: 14px;
    }
    </style>
    <script>
// -------------
var popup = null;
// -------------
document.addEventListener("DOMContentLoaded", function () {
    document.getElementById("map").addEventListener("mousemove", function(event) {
        doMove(event);
        });
    popup = document.getElementById("popup");
    popup.setAttribute("visibility", "hidden");
    });
// -------------
function doEnter(which){
    popup.innerHTML = which.id;
    popup.setAttribute("visibility", "visible");
    };
function doLeave(which){
    popup.setAttribute("visibility", "hidden");
    };
function doMove(what){
    popup.setAttribute("style", "left: "+what.pageX + 5+"; top: "+what.pageY + 5);
    };
// -------------
</script>
</head>
<body>
    <div id="map">
        <div id="popup" visibility="hidden" style="left: 0; top: 0"></div>
        <svg xmlns="http://www.w3.org/2000/svg" width="918" height="582" viewBox="0 0 918.4 582.5">
            <g id="California" onmouseenter="doEnter(this)" onmouseleave="doLeave(this)"><path d="M122.7,385.9,103,383.2l-10-1.5-.5-1.8v-9.4l-.3-3.2-2.6-4.2-.8-2.3-3.9-4.2L82,351.9l-2.7-.2-3.2-.8-.3-1,1.5-.6-.6-3.2L75.2,344l-4.8-.8-3.9-2.1-1.1-2.3L62.8,334l-2.9-3.1H57l-3.9-2.1L48.6,327l-4.2-.5L42,323.8l.5-1.9,1.8-7.1.8-1.9v-2.4l-1.6-1-.5-2.9L41.5,304l-3.4-5.8-1.3-3.1-1.5-4.7-1.6-5.3-3.2-4.4-.5-2.9.8-3.9h1.1l2.1-1.6,1.1-3.6-1-2.7-2.7-.5-1.9-2.6-2.1-3.7-.2-8.2.6-1.9.6-2.3.5-2.4-5.7-6.3V236l.3-.5.3-3.2-1.3-4-2.3-4.8L17.5,219l-1.8-3.9,1-3.7.6-5.8,1.8-3.1.3-6.5-1.1-3.6-1.6-4.2L14,184l.8-3.2,1.5-4.2,1.8-.8.3-1.1,3.1-2.6,5.2-11.8.2-7.4,1.69-4.9,38.69,11.8,25.6,6.6-8,31.3-8.67,33.1L88.84,250,131,312.3l17.1,26.1-.4,3.1,2.8,5.2,1.1,5.4,1,1.5.7.6-.2,1.4-1.4,1-3.4,1.6-1.9,2.1-1.7,3.9-.5,4.7-2.6,2.5-2.3,1.1-.1,6.2-.6,1.9,1,1.7,3,.3-.4,1.6-1.4,2-3.9.6ZM48.8,337l1.3,1.5-.2,1.3-3.2-.1-.6-1.2-.6-1.5Zm1.9,0,1.2-.6,3.6,2.1,3.1,1.2-.9.6-4.5-.2-1.6-1.6Zm20.7,19.8,1.8,2.3.8,1,1.5.6.6-1.5-1-1.8-2.7-2-1.1.2v1.2ZM70,365.5l1.8,3.2,1.2,1.9-1.5.2-1.3-1.2a9.72,9.72,0,0,1-.7-1.9v-2.2Z" transform="translate(-9 -6.4)"></path></g>
            <g id="Nebraska" onmouseenter="doEnter(this)" onmouseleave="doLeave(this)"><path d="M470.3,204.3l-1-2.3-.5-1.6-2.9-1.6-4.8-1.5-2.2-1.2-2.6.1-3.7.4-4.2,1.2-6-4.1-2.2-2-10.7.6L388,189.9l-35.6-2.2-4.3,43.7,33.1,3.3-1.4,21.1,21.7,1,40.6,1.2,43.8.6h4.5l-2.2-3-2.6-3.9.1-2.3-1.4-2.7-1.9-5.2-.4-6.7-1.4-4.1-.5-5-2.3-3.7-1-4.7-2.8-7.9-1-5.3Z" transform="translate(-9 -6.4)"></path></g>
        </svg>
    </div>
</body>
</html>

Multiple thumbnails from video on client side (pure JS)

I am trying to generate multiple thumbnails from video loaded on client side by URL.createObjectURL. In my code are correctly generated canvas for each thumbnail, BUT I am not able to put images to canvas :-). Can somebody show me correct solution?

const fileInput = document.querySelector('#input-video-file');
const video = document.getElementById('video');

fileInput.addEventListener('change', (e) => {
  video.src = URL.createObjectURL(e.target.files[0]);
  video.onloadedmetadata = function() {
    const duration = video.duration;
    const sample_duration = duration / 10;
    for (var i = 1; i < duration; i += sample_duration) {
      console.log(gen_thumb(i));
    }
  };
});

async function gen_thumb(thumb_time) {
  video.currentTime = thumb_time;
  const canvas = document.createElement("canvas");
  canvas.width = video.videoWidth;
  canvas.height = video.videoHeight;
  canvas.id = video.currentTime;
  canvas.getContext('2d').drawImage(video, 0, 0, video.videoWidth, video.videoHeight);
  document.body.appendChild(canvas);
  return;
}
<div id="app">
  <input id="input-video-file" type="file" accepts="video/mp4">
  <video id="video" controls></video>
</div>

How to dynamically set a tooltip using jQuery with data from a GET request?

I’m trying to add a tooltip to table rows based on data fetched via an AJAX request. The goal is to display additional info when the user hovers over a row in a specific table. Here’s the code I’m currently using:

function tooltip(event) {
    const sor = event.target.closest('tr');
    if (!sor) return;

    const tabla = sor.closest('table');
    const tablaNev = tabla.id.replace('Tabla', '');
    console.log(tablaNev);

    const mezo = Array.from(sor.children).map((cella) => cella.innerText);
    console.log(mezo);

    if (tablaNev === "tablazat0") {
        const id = mezo[0];
        $.get(`/bevetel?id=${id}`, function(data) {
            if (data && data.length > 0) {
                const osszesDarab = data[0].OsszesDarab;
                const osszesBevetel = data[0].OsszesBevetel;
                $(sor).attr(
                    "title",
                    `Összes darab: ${osszesDarab}, Összes bevétel: ${osszesBevetel} Ft`
                );
            }
        });
    }
}

$(document).on('mouseover', '#tablazat0 tbody tr', tooltip);
<div class="row col-12 justify-content-center" style="height: calc(100vh - 100px);">
    <div class="col-lg-5 h-100 mb-5" style="overflow: auto;">
        <h2 id="tablazatCim0" class="tablazatCim"></h2>
        <table id="tablazat0" class="table table-striped table-bordered table-hover table-responsive-xs">
            <thead id="tablazatHead0"></thead>
            <tbody id="tablazatBody0"></tbody>
        </table>
    </div>
    <div class="col-lg-5 h-100 mb-5" style="overflow: auto;">
        <h2 id="tablazatCim1" class="tablazatCim"></h2>
        <table id="tablazat1" class="table table-striped table-bordered table-hover table-responsive-xs">
            <thead id="tablazatHead1"></thead>
            <tbody id="tablazatBody1"></tbody>
        </table>
    </div>
</div>

It mostly works, but sometimes the tooltip doesn’t appear unless I move the mouse away and back again. I assume this is because the title attribute is added after the initial mouseover.

Question:
How can I ensure the tooltip appears immediately after the AJAX call sets the title? Is there a better way to dynamically update tooltips like this using jQuery?

Any suggestions or improvements are welcome. Thanks in advance!

Which of these JavaScript syntaxes will produce the same result everytime or is either of these options better? [closed]

So I am currently learning JavaScript and for one of my assignments I got marked incorrect but the solution reproduces the same result for all calls. In addition there is only on key difference(see code below). More for learning purposes interested in knowing why one is better than the other if they produce the same result and take up similar amount of lines.

<!– begin snippet: js hide: false console: true babel: false babelPresetReact: false babelPresetTS: false –>

// Correct One
const numberDigits = x => {
  let numString = '';
  if (x >= 0 && x <= 9){
    numString = 'One digit: ' + x;
  }else if (x >=10 && x <= 99){
    numString = 'Two digits: ' + x;
  }else {
    numString = 'The number is: ' + x;
  }
  return numString;
};

console.log(numberDigits(10));

// My answer

const numberDigits = (x) => {
if (x >= 0 && x <= 9){
  return `One digit: ${x}`
} else if (x >= 10 && x <= 99){
  return `Two digit: ${x}`
} else if (x <= -1 || x >= 100){
  return `The number is: ${x}`
}
};
console.log(numberDigits(10));

<!– end snippet –>

How to make a part of an object in a three.js scene transparent as the camera moves away from it

I have made canvas in my website rendered with a scene where scene.background = none. Therefore the color gradient of the div behind the canvas is inherited. I have tried using the scene.fog property but after the far-distance the object just turns into the fog color specified. How to make the object completely disappear when far distance is up, ie. if possible, how to make the fog the same color as my background.