Q: how to make loop for a cube going up and down in three js 
This example code the box only moves up I want it move up and down

    BoxGeo = new HREE.BoxGeometry(10,10,10)
    BoxMat = new THREE.MeshPhongMaterial({
      color: 0xf3e54f
    }),
    cab = new THREE.Mesh ( BoxGeo, BoxMat);
    scene.add(cab);
   
cab.position.y  += 1;


A: Since Math.random() gives you numbers in the [0, 1] range, you can change this range to  [-1, 1] with a simple equation:
let displacement = (Math.random() - 0.5) * 2.0;
cab.position.y += displacement;


A: You need Math.sin() in your animation loop in order to move the object up and down smoothly.
cab.position.y = Math.sin(elapsedTime) + 1

