如何解决FCC 25 + 5时钟计时器未到达00:00
我一直在进行免费代码训练营的25 + 5时钟挑战,其中6项测试一直失败,结果仍然相同,说“计时器未达到00:00”,但确实成功了当我看着它倒数时为零。这个版本是用香草JS完成的,我现在看到在React中可能会更好。有什么想法吗?
这是我的CodePen:https://codepen.io/mplatt212/pen/OJNxJJr
以下是最相关的JS:
const reset = document.querySelector('#reset');
const startStop = document.querySelector('#start_stop');
const breakLabel = document.querySelector('#break-label');
var breakLength = document.querySelector('#break-length');
const breakDown = document.querySelector('#break-decrement');
const breakUp = document.querySelector('#break-increment');
const sessionLabel = document.querySelector('#session-label');
const sessionLength = document.querySelector('#session-length');
const sessionDown = document.querySelector('#session-decrement');
const sessionUp = document.querySelector('#session-increment');
var timerLabel = document.querySelector('#timer-label');
var timeLeft = document.querySelector('#time-left');
var beep = document.querySelector('#beep');
var toggle = false;
breakLength.innerHTML = '5';
sessionLength.innerHTML = '25';
timeLeft.innerHTML = '25:00';
var timer = (parseInt(timeLeft.innerHTML.split(':')[0]) * 60 * 1000) + (parseInt(timeLeft.innerHTML.split(':')[1]) * 1000);
breakTimer = () => {
let breakTime = parseInt(breakLength.innerHTML) * 60 * 1000;
let breakInterval = setInterval(() => {
if(breakTime == 0){
timer = parseInt(sessionLength.innerHTML) * 60 * 1000;
timerStart();
timerLabel.innerHTML = 'Session';
clearInterval(breakInterval);
//beep.play();
}
if(toggle){
timeLeft.innerHTML = msToTime(breakTime);
breakTime -= 1000;
} else {
clearInterval(breakInterval);
return;
}
},1000)
}
timerStart = () => {
let sessionInterval = setInterval(() => {
if(timer == 0){
breakTimer();
timerLabel.innerHTML = 'Break';
clearInterval(sessionInterval);
beep.play();
return;
}
if(toggle){
timer -= 1000;
timeLeft.innerHTML = msToTime(timer);
} else {
clearInterval(sessionInterval);
return;
}
},1000)
};
如果您需要进一步说明,请告诉我。谢谢您的时间。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。