Skip to content
This repository was archived by the owner on Jul 4, 2025. It is now read-only.
This repository was archived by the owner on Jul 4, 2025. It is now read-only.

in second task (cancel counting) #203

@artsrunimargaryanfd

Description

@artsrunimargaryanfd

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.
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions