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

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