setTimeout(function, milliseconds)
<html>
<body>
<script>
function delayFunction() {
//display the message on web after 3 seconds on calling delayFunction
document.write('<h3> Welcome to lidihuo <h3>');
}
</script>
<b> Example of delay the execution of function <b>
<p id="t1"></p>
<button onclick = "setTimeout(delayFunction, 3000)"> Click Here </button>
</body>
</html>
setInterval(function, milliseconds)
<html>
<body>
<script>
function waitAndshow() {
//define a date and time variable
var systemdate = new Date();
//display the updated time after every 4 seconds
document.getElementById("clock").innerHTML = systemdate.toLocaleTimeString();
}
//define time interval and call user-defined waitAndshow function
setInterval(waitAndshow, 4000);
</script>
<h3> Updated time will show in every 4 seconds </h3>
<h3> The current time on your computer is: <br>
<span id="clock"></span> </h3>
</body>
</html>
<html>
<body>
<script>
function waitAndshow() {
//display the message on web on calling delayFunction
document.write('<h3> Welcome to lidihuo <h3>');
}
</script>
<h3> A string will show in every 4 seconds </h3>
<!-- call user-defined delayFunction after 4 seconds -->
<button onclick = "setInterval(waitAndshow, 4000)"> Click Here </button>
</body>
</html>
A string will show in every 4 seconds
<html>
<body>
<script>
function waitAndshow() {
var systemdate = new Date();
document.getElementById("clock").innerHTML = systemdate.toLocaleTimeString();
}
function stopClock() {
clearInterval(intervalID);
}
var intervalID = setInterval(waitAndshow, 3000);
</script>
<p>Current system time: <span id="clock"> </span> </p>
<!-- button to stop showing time in a regular interval -->
<button onclick = "stopClock();" > Stop Clock </button>
</body>
</html>