Здравствуйте
Решил сделать небольшую программу в браузере на js,
суть в том что при нажатии на Взять
идёт запись времени когда была нажата кнопка, и когда текущее время больше того времени меняется цвет рамки, при нажатии на кнопку Сдать должна выполнятся функция которая отметин выполнение первой и будет сравнивать новое время и задавать другие цвета, но это не работает
var localstor1
var now1
var all1 = window.setInterval(m1, 1000)
var all1_2 = window.setInterval(m1_2, 1000)
function m_start1() {
all1 = window.setInterval(m1, 1000)
all1_2 = window.setInterval(m1_2, 1000)
clearInterval(all2)
clearInterval(all2_2)
now1 = new Date();
now1.setSeconds(now1.getSeconds() + 10);
localStorage.time1 = now1
localstor1 = localStorage.time1
document.getElementById('img1').style.borderColor = 'green';
}
function m1() {
start_time = new Date();
}
function m1_2() {
console.log(localStorage.time1)
console.log(start_time)
document.getElementById('img1').style.borderColor = 'yellow';
if (new Date(start_time) >= new Date(localStorage.time1)) {
document.getElementById('img1').style.borderColor = 'red';
}
m1()
}
var localstor2
var now2
var all2 = window.setInterval(m2, 1000)
var all2_2 = window.setInterval(m2_2, 1000)
function m_stop1() {
all2 = window.setInterval(m2, 1000)
all2_2 = window.setInterval(m2_2, 1000)
window.clearInterval(all1)
window.clearInterval(all1_2)
now2 = new Date();
now2.setSeconds(now2.getSeconds() + 10);
localStorage.time2 = now2
localstor2 = localStorage.time2
document.getElementById('img1').style.borderColor = 'purple';
}
function m2() {
start_time = new Date();
}
function m2_2() {
console.log(localStorage.time2)
console.log(start_time)
document.getElementById('img1').style.borderColor = 'purple';
if (new Date(start_time) >= new Date(localStorage.time2)) {
document.getElementById('img1').style.borderColor = 'green';
}
m2()
}