45 lines
895 B
JavaScript
45 lines
895 B
JavaScript
|
function sayHi(){
|
||
|
console.log('Hello');
|
||
|
}
|
||
|
|
||
|
setTimeout(sayHi, 1000);
|
||
|
|
||
|
function sayHi2(phrase, who){
|
||
|
console.log(phrase + ',' + who);
|
||
|
}
|
||
|
setTimeout(sayHi2, 100, "Hi", "John");
|
||
|
|
||
|
|
||
|
let timerId = setInterval(()=>console.log(('tick')), 1000);
|
||
|
|
||
|
setTimeout(() => {clearInterval(timerId); console.log('stop!')}, 5000);
|
||
|
|
||
|
timerId = setTimeout(function tick(){
|
||
|
console.log('tick');
|
||
|
timerId = setTimeout(tick, 1000);
|
||
|
}, 1000)
|
||
|
|
||
|
function printNumbers(from, to){
|
||
|
let cur = from
|
||
|
|
||
|
let timerId = setInterval(() => {
|
||
|
console.log(cur)
|
||
|
if(cur == to){
|
||
|
clearInterval(timerId);
|
||
|
}
|
||
|
cur += 1;
|
||
|
}, 1000);
|
||
|
}
|
||
|
function printNumbers2(from, to){
|
||
|
cur = from
|
||
|
setTimeout(function go() {
|
||
|
console.log(cur);
|
||
|
if(cur < to){
|
||
|
setTimeout(go, 1000);
|
||
|
}
|
||
|
cur++;
|
||
|
}, 1000)
|
||
|
}
|
||
|
printNumbers(10, 15);
|
||
|
printNumbers2(10, 15);
|