I got a bit confused with the setTimeout command. The following code takes a text and gives back the single words in the console.log() field. But of course the process is caluclated immediately. I want to setTimeout the process, so the code will give me for example one word per second. I'm a bit stuggleing with the nested if condition in a for loop and didn't manage to find the solution in on this board or code it myself.
If you can help me, that would be awesome. Thanks a lot. :)
Robert
text = "test text bla blah blah blah Eric \
blah blah blah Eric blah blah Eric blah blah \
blah blah blah blah blah Eric";
var space = " ";
var h = 0;
var hits = [];
var word;
for (var h=0; h < text.length ; h++){
if (text[h]== space){
h=h+1;
console.log(word);
hits=[];
}
hits.push(text[h]);
var word = hits.join("");
}
if (h=text.length)
{
console.log(word);
}