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

126
Visualizações
the problem with writing a script for animated text output

I can't understand what the problem is, I'm writing a script that will have to output the text on its own, as if someone is typing, but I'm constantly throwing out the same error, do not tell me what can be done in this case, I will be grateful.

the error is that the substring method does not work Uncaught TypeError: Cannot read properties of undefined (reading 'substring')

let quoteArray = [];
let index = 0;
let textPosition = 0;
let flag = true;
let destination = document.querySelector('#typedtext');

window.addEventListener('load', typewriter);

function loadQuote() {
const url = "https://api.quotable.io/random";

fetch(url)

.then(response => {
    if(response.ok) {
        return response.json();
    } else {
        console.log(response.status);
    }
})

.then(data => {
    quoteArray[index] = data.content;
});

}

function typewriter(){
if(flag) {
    loadQuote();
    quoteArray[index] + ' ';
    flag = false;
}

destination.innerHTML = quoteArray[index].substring(0, textPosition); the error is here

if(textPosition++ != quoteArray[index].length){
    setTimeout('typewriter()', 100);
} else {
    quoteArray[index] = ' ';
    setTimeout('typewriter()', 3000);
    textPosition = 0;
    flag = true;
}

}

about 4 years ago · Juan Pablo Isaza
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