JavaScript setInterval() Function - JavaScript Tutorial 111

preview_player
Показать описание
Notes for You:: JavaScript setInterval() Function - JavaScript Tutorial 111
JavaScript setInterval(functionName,timeInterval) function:
- executes a function repeatedly after every specified time interval

JavaScript clearInterval(handlerName) function:
- stops executing a function pointed by the handler

Example Code 1: Display Counter in JavaScript.

<span id="spnCounter"></span>

<script type="text/javascript">

var counter = 5;
var counterHandler = setInterval(changeCounter, 1000);

function changeCounter()
{
counter--;

if(counter == 0)
clearInterval(counterHandler);
}
</script>

Example Code 2: Display Clock in JavaScript.

<span id="hours">00</span> : <span id="minutes">00</span> : <span id="seconds">00</span>

<script type="text/javascript">

var seconds = 60;
var minutes = 0;
var hours = 0;

var timerHandler = setInterval(changeTime,1000);

function changeTime()
{

seconds--;
if(seconds==0)
{
seconds = 60;
minutes++;
if(minutes==60)
{
minutes=0;
hours++;
if(hours==24)
{
seconds=60;
minutes=0;
hours=0;
}
}
}
}
</script>

Note:
- replace < with less-than symbol.
- replace > with greater-than symbol.

=========================================

Follow the link for next video:

Follow the link for previous video:

=========================================

JavaScript Tutorials Playlist:-

=========================================
Watch My Other Useful Tutorials:-

jQuery Tutorials Playlist:-

jQuery UI Tutorials Playlist:-

Bootstrap Tutorials Playlist:-

=========================================

► Subscribe to our YouTube channel:

► Visit our Website:

=========================================
Hash Tags:-
#ChidresTechTutorials #JavaScript #JavaScriptTutorial
Рекомендации по теме
Комментарии
Автор

👍Every video on my channel is made with Love and Hard work, So don't forget to Like, Comment & Share.
👉Please do Subscribe, Hit the bell icon & Enjoy Learning. It's FREE.

ChidresTechTutorials
Автор

Please Sir, keep coding, keep teaching, keep doing it. Amazing explanation!

loscolaro
Автор

Thanks for the video sir.

Sir, why did you convert that counter to string?

ayindejubrilolarewaju