Response:
Code:
const example = {
scope: null,
tokens: ['alpha','bravo','charlie','delta','echo'],
array: []
};
example.message = (args) => {
if(args.log) console.log(args.log);
if(args.msg) document.getElementById('viewport').innerHTML = args.msg;
};
setTimeout(() => {
example.array.push(example.tokens[0])
}, 250);
setTimeout(() => {
example.array.push(example.tokens[1])
}, 500);
setTimeout(() => {
example.array.push(example.tokens[2])
}, 750);
setTimeout(() => {
example.array.push(example.tokens[2])
}, 1000);
setTimeout(() => {
example.array.push(example.tokens[4])
}, 1250);
example.process = () => {
setTimeout(() => {
example.message({ msg: example.array, log: example.tokens[0] });
}, 250);
setTimeout(() => {
example.message({ msg: example.array, log: example.tokens[1] });
}, 500);
setTimeout(() => {
example.message({ msg: example.array, log: example.tokens[3] });
}, 750);
setTimeout(() => {
example.message({ msg: example.array, log: example.tokens[2] });
}, 1000);
setTimeout(() => {
example.message({ msg: example.array, log: example.tokens[4] });
}, 1250);
};
example.init = () => {
example.process();
};
document.addEventListener('DOMContentLoaded',example.init);