Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

152
Vistas
Unable to call function in javascript

Just a warning- I'm new to javascript. For some reason nothing is being returned when I call impureSwipeRight() inside of moveRight(). I know the actual code works, as when they're all part of the same function the code does exactly what I want it to do. So I'm assuming there's an issue with actually calling the function?

     function impureSwipeRight(i){
        let totalOne = squares[i].innerHTML;
        let totalTwo = squares[i+1].innerHTML;
        let totalThree = squares[i+2].innerHTML;
        let totalFour = squares[i+3].innerHTML;
        //the above stores the inner value of each square
        //on that row, starting from the left
        let row = [parseInt(totalOne), parseInt(totalTwo), parseInt(totalThree), parseInt(totalFour)]
        //create an array storing the entire row
    
        let filterRow = row.filter(num => num)
        //filter out numbers from rows and store the numbers
        //as a new array.
        let missing = 4 - filterRow.length
        //checking how many 0s there are now in the row
        let zeros = Array(missing).fill(0)
        //creating a new array filled with these 0s
        let newRow = zeros.concat(filterRow)
        return newRow

    }

    //swiping right
    function moveRight(){
        for(let i=0; i <16; i++){
        //loops over all of grid
            if(i%4 === 0){
            //define rows using modulus. If i MOD 4 = 0,
            //this means that the square is the start of each row.

                newRow = impureSwipeRight(i)
                squares[i].innerHTML = newRow[0]
                squares[i+1].innerHTML = newRow[1]
                squares[i+2].innerHTML = newRow[2]
                squares[i+3].innerHTML = newRow[3]
                //replaces each value with the new array 

            }
        }
    }
    moveRight()

about 4 years ago · Juan Pablo Isaza
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda