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

226
Visualizações
elemento aleatorio de una matriz no está definido

Hice mi intento como codificador principiante de JS y modifiqué una aplicación generadora de cotizaciones a partir de una matriz con solo hacer clic en un botón. Logré mostrar el siguiente elemento cada vez que presiono el botón. Sin embargo, en el tutorial, los elementos se mostraban al azar, así que seguí las instrucciones, pero en lugar de una cita aleatoria, aparece "indefinido". Estoy atascado. Me parece que he hecho todo correctamente, pero puede que me haya resbalado en alguna parte. ¿Alguien puede ayudarme?

 let btn = document.getElementById("btn"); let output = document.getElementById("output"); let quotes = [ "The greatest glory in living lies not in never falling, but in rising every time we fall. -Nelson Mandela", "The way to get started is to quit talking and begin doing. -Walt Disney", "Your time is limited, so don't waste it living someone else's life. Don't be trapped by dogma – which is living with the results of other people's thinking. -Steve Jobs", "If life were predictable it would cease to be life, and be without flavor. -Eleanor Roosevelt", "If you look at what you have in life, you'll always have more. If you look at what you don't have in life, you'll never have enough. -Oprah Winfrey", "If you set your goals ridiculously high and it's a failure, you will fail above everyone else's success. -James Cameron", "Life is what happens when you're busy making other plans. -John Lennon", ]; btn.addEventListener("click", function() { let randomQuote = quotes[Math.floor(Math.random() * quotes.lenth)]; output.innerHTML = randomQuote; });
 <h1>Quote Generator</h1> <div class="content"> <button id="btn">Press for a new Quote!</button> <p id="output">Press the button to generate a quote.</p> </div>

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

Tu código es perfecto solo quotes.lenth --> quotes.length :)

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