'How can I add a string to an array when a checkbox is checked?
These are my strings and their speeds at which they will be displayed
var typed = new Typed(".auto-input", {
strings: ["Hi, blahblahblah.", "blahblahblah...", "...blahblahblah?"],
typeSpeed: 75,
backSpeed: 75,
loop: true
});
This is my code for when my checkbox is checked
var checkbox = document.getElementById('checkbox');
checkbox.addEventListener('change', () => {
document.body.classList.toggle('dark');
});
I tried an if statement
if (document.body.classList.toggle('dark')) {
typed.push(["lorem"]);
}
But then i realized, i think i need to select the "strings" in my "typed" vaiable. I'm not quite sure how to do that. I apologize in advance for any mistakes, this is my first question posted on StackOverflow.
Solution 1:[1]
As you want to push "lorem" into strings inside Typed, your if statement should look like:
if (document.body.classList.toggle('dark')) {
typed.strings.push("lorem");
}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Rani Giterman |
