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

147
Views
adding statement to increment value by 1 js

Hi im really new to javascript and stuck on a textbook exercise where I increase the increment of variable i by 1 to be able to continuing listing the inputs. Here is my code so far, can anyone guid me on what I am doing incorrect thank you

<body>
   <header>
      <h1>
         Project 2 Test 1
      </h1>
   </header>

   <article>
      <div id="results">
          <ul>
             <li id="item1"></li>
             <li id="item2"></li>
             <li id="item3"></li>
             <li id="item4"></li>
             <li id="item5"></li>
          </ul>
          <p id="resultsExp"></p>
      </div>
      <form>
          <fieldset>
            <label for="wishList" id="placeLabel">
              Type the name of a wish list item, then click Submit:
            </label>
            <input type="text" id="wishList" />
          </fieldset>
          <fieldset>
            <button type="button" id="button">Submit</button>
          </fieldset>
      </form>
   </article>
   <script>
      i = 1;
      listitem = "";
      function processitems() {
         if (i<= 5) {
            listitem ="item" +i;
            document.getElementById(listitem).innerHTML = document.getElementById("wishList").value;
            document.getElementById("wishlist").value ="";
            if (i===5) {
               document.getElementById("resultsExp").innerHTML = "Your wish list has been submitted";
            }
//inside the processitems() function of the main if statement, after the nested if statement, add a statement to increment the value of i by 1.
          i =+1;
         }
      }
      var btn = document.getElementById("button");
      if (btn.addEventListener) {
         btn.addEventListener("click", processitems, false);
      } else if (btn.attachEvent) {
         btn.attachEvent("onclick", processitems);
      }
   </script>
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

i =+1; is assigning 1 to i. You should be doing i += 1 instead:

<body>
  <header>
    <h1>
      Project 2 Test 1
    </h1>
  </header>

  <article>
    <div id="results">
      <ul>
        <li id="item1"></li>
        <li id="item2"></li>
        <li id="item3"></li>
        <li id="item4"></li>
        <li id="item5"></li>
      </ul>
      <p id="resultsExp"></p>
    </div>
    <form>
      <fieldset>
        <label for="wishList" id="placeLabel">
              Type the name of a wish list item, then click Submit:
            </label>
        <input type="text" id="wishList" />
      </fieldset>
      <fieldset>
        <button type="button" id="button">Submit</button>
      </fieldset>
    </form>
  </article>
  <script>
    i = 1;
    listitem = "";

    function processitems() {
      if (i <= 5) {
        listitem = "item" + i;
        document.getElementById(listitem).innerHTML = document.getElementById("wishList").value;
        document.getElementById("wishList").value = "";
        if (i === 5) {
          document.getElementById("resultsExp").innerHTML = "Your wish list has been submitted";
        }
        //inside the processitems() function of the main if statement, after the nested if statement, add a statement to increment the value of i by 1.
        i += 1;
      }
    }
    var btn = document.getElementById("button");
    if (btn.addEventListener) {
      btn.addEventListener("click", processitems, false);
    } else if (btn.attachEvent) {
      btn.attachEvent("onclick", processitems);
    }
  </script>

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!