Build a Pomodoro Clock Failed tests

Build a Pomodoro Clock Failed tests
0

#1

Tell us what’s happening:
Can you help me with test?
Pomoodoro works correct, but tests failed…
Your code so far


Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:62.0) Gecko/20100101 Firefox/62.0.

Link to the challenge:
https://learn.freecodecamp.org/front-end-libraries/front-end-libraries-projects/build-a-pomodoro-clock


#2

Hey @wulf1243,
Took a quick look at your code, and it looks like your setInterval waits until this.state.session reaches -1 before resetting timers. That should pass at least one of the tests.


#4

This doesn’t work…

window.intervalId = setInterval(() =>{
			console.log(this.state.session);
			this.setState({
				session: this.state.session - 1
			});
			if (this.state.session == 0) {
				if(this.state.breackLabel == "Session") {
					this.setState({
						breackLabel: "Breack"
					});
				}
				else {
					this.setState({
						breackLabel: "Session"
					});
				};
			}
			if(this.state.session == 0 && this.state.breackLabel == "Breack") {
				setTimeout(()=> {this.setState({
					session: this.state.breackLength * 60
				});}, 1000);
			}
			if (this.state.session == 0 && this.state.breackLabel == "Session") {
				setTimeout(()=> {this.setState({
					session: this.state.sessionLength * 60
				});}, 1000)
			}
		}, 1000);
		window.intervalArr.push(window.intervalId);
		if (window.intervalArr.length % 2 == 0) {
			max_id = setTimeout(function () {});
			while (max_id--) {
    			clearTimeout(max_id);
			};
		};

#5

Right, the way it is written right now doesn’t work, but there are a lot of topics we would have to go over so I’ll let you explore this. One of the main issues with the code above is that this.setState is asynchronous, but is written synchronously.