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

148
Vistas
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 Respuestas
Responde la pregunta

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 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