
Originally Posted by
kaiser0427
I want this array to write hello wait 1 second and write world wait a second and write !.........
html file
HTML Code:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>hello world !</title>
<script src="hw.js"></script>
</head>
<body>
<p id="here"></p>
</body>
</html>
save file as hw.js or change html to suit
Code:
var hwArr = (function () {
var myArr, index, here;
function test() {
var str = '',
i;
if (index < 4) {
for (i = 0; i < index; i += 1) {
str += myArr[i] + ' ';
}
index += 1;
here.innerHTML = str;
setTimeout(function () {test(); }, 1000);
}
}
function initAll() {
myArr = ['Hello', 'World', '!'];
index = 1;
here = document.getElementById('here');
test();
}
return ({
start: initAll
});
}());
window.onload = function () {
hwArr.start();
};
Bookmarks