so I’m trying to create func to find 3 letters words for a long text.
const fullstory =
"One advanced etc etc"
document.querySelector("#story").innerHTML = fullstory;
const cutspace = fullstory.split(" ");
document.querySelector("#three").addEventListener("click", find3);
function find3() {
for (i = 0; i < cutspace.length; i++)
if (cutspace[i].length<=3){
//cutspace[i].style // not working
};
}
what am i missing?
2
Answers
It seems like you’re trying to change the style of words in your text with a length less than or equal to 3 characters.
"Since ‘cutspace[i]’ is an array, directly changing its style using ‘.style’ is not applicable. To address this, you should restore the array value with the desired style and then proceed with the necessary modifications."
I believe the following code snippet may be useful for your solution.
The below code uses a
regex
match to find all the three-letter words in a given text.