everyone! I am new to javascript. Suppose I have a video and I want that when it is played for a certain number of seconds (say 5 seconds), my_function will execute (for example, the word 'five' should be displayed in the console). For some reason, the code below correctly displays a current number of seconds of video, but does not display the word in the console.
html:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Text</title>
</head>
<body>
<div class="container">
<video width="400" controls id="video">
<source src="video/video.mp4" type="video/mp4">
Your browser does not support HTML5 video.
</video>
<span class="timelapse" id='current'> </span>
</div>
<button id='getTime'>getTime</button>
</body>
<script src="js/script.js"></script>
</html>
script.js:
var aud = document.getElementById('video');
aud.ontimeupdate = function(){myFunction()};
function myFunction(){
document.getElementById('current').innerHTML = aud.currentTime;
if (aud.currentTime == 5.0){
console.log('Hello!');
}
};
Thank you!