Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

151
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!