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
How can I fill my array in JavaScript depending on user input?

How can I fill my array depending on user input instead of changing this array manualy in JavaScript?

How can I link my form in HTML to my javaScript ?

let move = ["L", "L", "R", "F", "N"];
let lastElement = move.slice(-1);
console.log(lastElement);

function finalPosition(move) {
    let countUp = 0, countDown = 0;
    let countLeft = 0, countRight = 0;
    let l = move.length;

    for (let i = 0; i < l; i++) {

        if (move[i] == 'F')
            countUp++;

        else if (move[i] == 'B')
            countDown++;

        else if (move[i] == 'L')
            countLeft++;

        else if (move[i] == 'R')
            countRight++;
    }
    document.write("Final Position: (" + (countRight - countLeft) + ", " + (countUp - countDown) + "," + lastElement + ")");
}

finalPosition(move);
about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

Ok two questions in one:

  • How can I fill my array depending on user input instead of changing this array manualy in JavaScript?

    Use .push() to add a value to your Array. For more info see here.

  • How can I link my form in HTML to my javaScript?

    1. Add an id to the form.

    2. Then load the form with:

      const theForm = document.getElementById("theFormId");
      

      Then you can work with the form in JavaScript.

about 4 years ago · Juan Pablo Isaza Denunciar
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