I’m doing the 25 + 5 Clock challenge now and am stuck on something that should be very simple. I’m trying to update this.state.breakLength when the break decrement button is clicked. However, nothing seems to be happening when the button is clicked, and the break length on the display is not getting updated.
What am I missing? See code below and thanks in advance for any help.
Wow I had no idea changing the z-index could have that effect. I removed that from the CSS and it is working now, thank you!
I’ve been trying to play around with the position of the buttons, changing them from absolute to relative, and using margin-left instead of left to reposition them. Whatever I do, they seem to move around though when the screen is resized. I’ll need to keep working on them to make it so that they don’t move. Perhaps the location of the button divs in the React code is what’s causing the trouble?
You can use absolute position for the buttons but you should use the offsets left/right/top/bottom and not margin for the positioning.
You need to make the container position: relative and make sure it has a fixed width (width: fit-content would work). Then use position: absolute for the buttons (not relative). Seeing as this is unlikely to be responsive giving the clock-container a fixed width is fine (although it is usually to be avoided otherwise).
If you do it correctly the buttons should stay where they are even if the screen size is changed.
Thank you @lasjorg . I’ve fixed it now so everything stays where it’s supposed to be when it’s resized…I’ve also added…a little FLARE to it . I think all the tests should pass now except for a few at the end. I still need to add audio. However, the tests are getting hung up and stuck on test 11 and not moving to the other tests. Any idea what might be causing the tests to hang there?
It looks like the reset is causing the issue. I didn’t look much at it but you are doing plain DOM manipulation which you should never do in React.
document.getElementById(
"time-left"
).innerHTML = `${globalSessionMinutes}:${globalSeconds}`;
//Update the time-left element with value of globalSessionMinutes and globalSeconds.
document.getElementById("timer-label").innerHTML = "Session";
document.getElementById(
"time-left"
).innerHTML = `${globalSessionMinutes}:${globalSeconds}`;
The elements should be referring to reactive state. You change the state and the DOM is updated with the changes. You do not manually change the DOM content.
@lasjorg Thanks for your feedback. I didn’t realize direct DOM manipulation within React was a no-no. The reason I did that, was because the setState({}) method does not seem to work within an interval. I’ve read there are ways around that, but they seemed somewhat complicated. I’ll have to read up on it more though, and figure out how to change the state from within an interval I guess, and then redo certain parts of the code.
Updated: I’ve tried commenting out all of the direct DOM manipulation and running the tests, but it still gets stuck on test 11. So I’m thinking it must be something else. Any other ideas? I’m lost.
I fixed that just now. I needed to update the code so that when the minutes got below 10, it added a “0” before the minute so it would be in the format mm:ss for minutes below 10. This threw off the IF statement that made it switch from session minutes to break minutes when 00:00 is shown on the timer.
I’ve managed to get 26 of 29 tests to pass. I can’t figure out why the last three aren’t passing though as the clock seems to be functioning as intended. Below are two of the errors I’m getting.
The only thing I can think of, is that instead of changing the value of sessionMinutes within the interval to the value of the globalBreakMinutesVariable when 00:00 time is reached, it wants me to call a new interval and clear the current interval. Could this be why the last three tests are failing?