<script language="javascript">
// random strings
var strings = ["How is it even possible?", "Have you ever heard about this?"];
var WriteLine = function(s)
{
var end=s.length, sc=s.split("");
for(counter = 0;counter<end;counter++)
{
setTimeout(function(){document.write(sc[counter]);},20);
// ^^^^^^^^^^^
}
}
strings.forEach(WriteLine);
</script>
It returns me that:
undefinedundefinedundefinedundefinedundefinedundefinedundefined
So the problem is that the variable sc
is out of scope due to setTimeout
function, I already have tried to use this