Time interval of JS doesn´t respond correctly

I am creating a landing page in which I am adding JS code with a function of typeEffect that function if I recognize it and execute it correctly. But when I add an interval for that function to execute it every so often, it ignores the time interval. I have reviewed the JS code with the company development team and in theory it is correct. I do not know if I have to see something with HubSpot. Can you help me review this issue, please? I add the JS code that I am using:

function typeEffect() {
var speed = 75;
var delay = $(‘h2’).text().length * speed + speed;
var text = $(‘h2’).text();
$(‘h2’).html(‘’);
var i = 0;
var timer = setInterval(function() {
if (i < text.length) {
$(‘h2’).append(text.charAt(i));
i++;
} else {
clearInterval(timer);
}
}, speed);
}

$( document ).ready(function() {
typeEffect();
setInterval (typeEffect(), 5000);
/*setTimeout(function(){
}, delay)*/
});

And I add the link about landing:

I commented to you that the title of: “¿QUÉ ES LA NUBE?” it is where I´m attaching this JS code.

Also I attach a screenshot where I´m add the script in my template.

If you need know something else plis let know.

I remain to your comments.

Thank and Regards

You’re close. There’s 2 ways to call setInterval. (1) is to pass a function object reference [in quotes], and (2) is to call an anonymous function that calls your main function

setInterval("typeEffect()", 1000)

setInterval(function(){
 typeEffect();
}, 1000)

If this answer helped, please, mark as solved :grinning_face_with_smiling_eyes:


tim@belch.io | forms.belch.io | Design your own Beautiful HubSpot Forms; No coding necessary.

Drop by and say Hi to me on slack.

Thanks @tjoyce

Its work with the first option.

Thanks very much.

Regards