Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

153
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda