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

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

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