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

140
Visualizações
¿Atascado en la declaración if en JavaScript?

Intenté esto pero no funciona

quiero ejecutar ambas declaraciones if (addTxt.textLength == 0) y if (headingTxt.textLength == 0) y luego, si ambas condiciones son verdaderas, entonces el bloque se ejecutará pero no funciona, ayúdame a resolver este problema

 // If user adds a note, add it to the localStorage let addBtn = document.getElementById('addBtn'); addBtn.addEventListener('click', function (e) { let addTxt = document.getElementById("addTxt"); let headingTxt = document.getElementById("headingTxt"); if (addTxt.textLength == 0) { alert("Please write something in text box!") } if (headingTxt.textLength == 0) { alert("Please Give some Heading To Your Note!") } else { let notes = localStorage.getItem("notes"); if (notes == null) { notesObj = []; } else { notesObj = JSON.parse(notes); } notesObj.push({text: addTxt.value, heading: headingTxt.value, date : new Date()}); localStorage.setItem("notes", JSON.stringify(notesObj)); addTxt.value = ""; // console.log(notesObj); showNotes(); } })
about 4 years ago · Juan Pablo Isaza
3 Respostas
Responde à pergunta

0

tengo la solucion

 // If user adds a note, add it to the localStorage let addBtn = document.getElementById('addBtn'); addBtn.addEventListener('click', function (e) { let addTxt = document.getElementById("addTxt"); let headingTxt = document.getElementById("headingTxt"); if (addTxt.value.length == 0) { alert("Please write something in text box!") } else if (headingTxt.value.length == 0) { alert("Please Give some Heading To Your Note!") } else { let notes = localStorage.getItem("notes"); if (notes == null) { notesObj = []; } else { notesObj = JSON.parse(notes); } notesObj.push({text: addTxt.value, heading: headingTxt.value, date : new Date()}); localStorage.setItem("notes", JSON.stringify(notesObj)); addTxt.value = ""; // console.log(notesObj); showNotes(); } })
about 4 years ago · Juan Pablo Isaza Relatório

0

puedes hacer algo como esto.

 if (addTxt.value.length === 0 && headingTxt.value.length === 0) { //do this } else { if (addTxt.value.length === 0) { alert("Please write something in text box!"); return; //stop further logic in this function } if (headingTxt.value.length === 0) { alert("Please Give some Heading To Your Note!"); return; //stop further logic in this function } }
about 4 years ago · Juan Pablo Isaza Relatório

0

es simple. Solo los agrupas en una condición:

 if (addTxt.textLength == 0 && headingTxt.textLength == 0) { }
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