Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

in second task (cancel counting) #203

Open
artsrunimargaryanfd opened this issue May 30, 2017 · 0 comments
Open

in second task (cancel counting) #203

artsrunimargaryanfd opened this issue May 30, 2017 · 0 comments

Comments

@artsrunimargaryanfd
Copy link

Here is my code and it is tested and working properly in js console, but for some reason the app is not accepting it as correct answer. Also if it is helpful we have checked that answer provided by you here (https://github.com/rmurphey/js-assessment-answers/blob/master/app/count.js) does not correctly working during counting. With that way you cant stop the counting whenever you want (mean that you can apply cancel method only right after calling count method: instance.count().cancel()).

Here is our version:

count: function(start,end) {
var Timer = function(start,end){
var timeout;
var that = this;
this.startCount = function() {

		console.log(start);
		timeout = setTimeout(function() {
			if(start < end) {
				start++;
				return that.startCount(start, end);
			}
			else {
				clearTimeout(timeout);
			}
		},100);

	}
	this.stopCount = function(){
		if(timeout !== undefined) {
			clearTimeout(timeout);
		}
	}

}
var timer = new Timer(start,end);
timer.startCount();

// Stop the counter when you want with stopCount() method.
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant