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

96
Views
Get the returned variable out of a function and into a document.write

Pretty new to this,

Just trying to get the form input into the generator and out the bottom display. The generator and display are connected just need to get the form input to feed into the generator now

Any help would be appreciated!

      </head>
      <body>
      <div class="background-color">
      <h1>Welcome to the Fibonacci Generator!</h1>

      <h2>Please input a number between 1 and 10</h2>

      <div class="container">
      <form class="pure-form">
       <input class="numberInputBox" autocomplete="off" id="name"
      type="number" placeholder="            Enter # Here!" />
      <button type="submit" class="btn btn-success heighttext">GO! 
      </button>
      </form>

      <script type="text/javascript">

      var nameInput = document.getElementById('name');

      document.querySelector('form.pure- 
       form').addEventListener('submit',
      function (e) {

       e.preventDefault();
      });

      </script>
      </div>
      <div class="display">
      <script type="text/javascript">
      </script>
      <h1>
      <script type="text/javascript">
      function fibonacciGenerator(n) {
        var seq = [0, 1];
        for (var i = 2; i < n; i++) {
          seq.push(seq.at(-1) + seq.at(-2));
        }
        seq.length = n;
        return seq;
      }

      document.write(fibonacciGenerator(10));
      </script>
      </h1>
       </div>
       </div>
       </div>
       </div>
       </div>
       </body>
       </html>
       <footer>
       <div class="footer">
       </div>
       </footer>
about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

Here's a very simple example of passing the result of a fibonacciGenerator function to document.write.

function fibonacciGenerator(n) {
  var seq = [0, 1];
  for (var i = 2; i < n; i++) {
    seq.push(seq.at(-1) + seq.at(-2));
  }
  seq.length = n;
  return seq;
}

document.write(fibonacciGenerator(10));

about 4 years ago · Juan Pablo Isaza Report

0

If you trying to get "result" by using document.getElementById, that doesn't work. getElementById return a tag from the DOM.

You the to attached the var "result" to some tag in you DOM.

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!