So my code passed all tests once, but not since. It fails test 27: play the audio at 00:00. I’m not sure why it is failing, nor can I recreate it passing the one time that it did. The only thing I have changed is CSS, so I don’t imagine that is it. If anyone is able to help it would be greatly appreciated. Also, is there any way to only run one test so I don’t have to keep running through the 5 minutes of test the other 26 tests require?
Here is my codepen:
Pomodoro Timer
Thank you in advance!
(edit: anyone = any way)
Can’t open to see code itself … Anyroad, the value you’re putting into element with id="time-left"
, use that in condition that when it’s “00:00”, will play sound. If it’s React, get it by ref, if it’s vanilla js, get it by id="beep"
. That you’ll now for sure if it is “00:00”.
Sorry, I think I put the correct link in now so you might be able to see the code. As it is I have the audio.play()
on the other side of the if (this.state.timeLeft >= 0)
statement. I have tried with with different values up to >=900 with the same result just to see if I could have the audio playing as the timer hit 00:00 (but not when it was still at 00:01 or above).
So audio is not playing at all? Maybe your markup for it isn’t good. This:
<audio preload="auto" ref={this.myRef} id="beep" src="http://soundbible.com/grab.php?id=2158&type=wav"></audio>
works for me. Notice this is react so there’s a ref and you can use id. Or something like this
var audio = new Audio('audio_file.mp3');
audio.play();
if it’s vanilla js.
The audio is playing (multiple time during the testing) but I guess it’s not playing as it hits 00:00, and instead plays as it switches to the next timer at xx:59.
So problem isn’t in audio, instead your timer goes from example: xx:01 to xy:59. Well check your timer variable if it shows “00:00”. Something:
if(timer==="00:00"){
console.log(timer);
alert(timer);
audio.play();
//other code to execute
}
You’re somewhere trimming to much time…
Thanks. Talking it out with you just made me realize I should put another if statement into my above 0 if statement to trigger the audio, not put it in the below 0 statement. It passed!
All tests? I’m asking 'cause mine doesn’t even if i check it and console.log it during tests.
Yep 29/29. Thank you for introducing me to the preload attribute of the audio tag, btw. This is a good situation for it.
Thanks. Btw, i’m also doing pomodoro in react. If you can solve some of problems i have?
I took a look and it seems like we went very different routes with how we measure time. I noticed you use the Date.now()
just for logging purposes in your state.timestamp. I use it to measure time passed, and grab just two time stamps (start of timer and pause of timer).
I also noticed that your code has it run the clearInterval()
at the same time it hits 0, without anytime displaying 0, which is throwing up the timer errors. I can’t seem to look at it with my react dev tools, so sorry I can’t be of more help.
Ok., from where i should remove clearInterval()
?