Passing Parameters Into This Function Not Working?
I am trying to build some re-usable code snippets that create a typewriter effect. It hides a paragraph and then replaces it with another paragraph with some js code that prints on
Solution 1:
When using ((id, text) => {})()
the function is called with zero argument. If you want to give args to this function please don't use IIFE, or using (id, text) => { ((id, text) => {})(id, text) }
.
https://codepen.io/1010543618/pen/MWWLxmN?editors=0110
consttypeWriter = (selector, text) => {
let letCounter = 0;
let cycle, classCounter;
let typewriter = text;
let speed = 50;
//Cycle through each id after done
cycle = document.querySelectorAll(selector);
functiontypeOut() {
if (letCounter < typewriter.length) {
for (classCounter = 0; classCounter < cycle.length; classCounter++) {
cycle[classCounter].innerHTML += typewriter.charAt(letCounter);
letCounter++;
}
setTimeout(typeOut, speed);
}
}
typeOut();
};
Post a Comment for "Passing Parameters Into This Function Not Working?"