Javascript Get Time Function Not Working

Javascript Get Time Function Not Working
0.0 0

#1

Hi folks,

I’m trying to get the “Start/Resume” button on my Pomodoro Clock to give the current time when pressed, but it is not working…can you give me some help? See jsfiddle here: https://jsfiddle.net/MenelikMakonnen/hzqz2uu7/

Javascript code:
`
$(document).ready(function(){

 $(".start-resume").click(function(){
 	$('.time-display').removeClass("on");
 	$('.time-display').addClass("on").html("Ready?");
 });


 $(".stop-reset").click(function(){
 	$('.time-display').removeClass("on").html("888888");
});

//----------create countdown visual (every 1 second)--------- 

var x = setInterval(function(){
	//get current time when user clicks "Start" button
	//can also use jQuery now method....will try later hahaha

	function myFunction(){
    	var d = new Date();
    	var n = d.getTime();
    	document.getElementById("number").innerHTML = n;
	};

	$(".start-resume").css('cursor', 'pointer').click(function(){

	});
});

`

HTML Code (excerpt):

`

	<div class="bottom-row">
		<div class="start-resume">
		<h3>Start/Resume</h3>	
		</div>
		<div class="pause">	
		<h2>PAUSE</h2>
		</div>
		<div class="stop-reset">
		<h3>Stop/Reset</h3>
		</div>
	</div>
`

I don’t know what the problem is?


#2

Where are you calling the function that will give you the current time? I recommend you add some console.log statements to you code so that you can see what it is doing.

Hope this points you in the right direction :slight_smile:

PS: you might want to take a look at how ofter your setInterval is running.