<html>
<head>
<title>lorem ipsum</title>
<style type="text/css">
body{
background-color:#222222;
margin:0px;
padding:0px;
}
#typed{
color:red;
font-size:150%;
float:left;
}
.cursor{
height:24px;
width:2px;
background:lawngreen;
float:left;
opacity:0;
animation:blink 0.75s linear infinite alternate;
}
@keyframes blink{
50% {
opacity:0;
}
100% {
opacity:1;
}
}
</style>
</head>
<body>
<div id="typed"></div>
<div class="cursor"></div>
</body>
<script type="text/javascript">
var i;
var txt='lorem ipsum';
var speed=50;
for (i=0; i<txt.length;i++){
setInterval(addLetter("typed"),speed);
}
function addLetter(word){
document.getElementById(word).innerHTML += txt.charAt(i);
i++;
}
</script>
</html>
I cannot see why it thinks it's wrong, but perhaps I'm just missing something. Chrome tells me that the error is an uncaught syntax error in the for loop, the error, it says, is the ")". I've been trying to figure it out all day long.
EDIT: What I'm trying to do is get the text in the variable, "txt" to pop up on screen as if being typed out. I fixed it with the below suggestion
Change ,
by ;
in for loop.
for (i=0; i<txt.length;i++){
Also, remove the }
before </script>
.