oven baking
let clock = document.getElementById("clock");
let timer = document.getElementById("timer");
let temp = document.getElementById("temp");
let knob = document.getElementById("knob");
let knob2 = document.getElementById("knob2");
let timerComplete = false;
let maxTemp = 160;
let tempInc = 10;
let timerLength = 20;
let tempCount = 0;
let timerId, countdownId, countdown;
let timerRunning = false;
// dispays time on display in 24 hour format.
function digitalTime() {
var date = new Date();
var hour = date.getHours();
var min = date.getMinutes();
var sec = date.getSeconds();
hour = checkNumber(hour);
min = checkNumber(min);
sec = checkNumber(sec);
clock.innerText = hour + " : " + min + " : " + sec;
var t = setTimeout(function () {
digitalTime();
}, 1000);
}
// checks if single digit, if so add zero to it
function checkNumber(k) {
result = k < 10 ? "0" + k : k;
return result;
}
// activate the time from the start
digitalTime();
// increments the temperature and stops when reached max
function increaseTemp() {
let displayTemp = temp.innerHTML;
if (displayTemp != "MAX: " + maxTemp) {
knob.style.webkitAnimationPlayState = "running";
let tempNumber = (tempCount += tempInc);
if (tempNumber > maxTemp) {
tempNumber = maxTemp;
}
temp.innerHTML = "TEMP: " + tempNumber;
if (tempNumber == maxTemp) {
temp.innerHTML = "MAX: " + maxTemp;
knob.style.webkitAnimationPlayState = "paused";
}
}
}
// increase the temperature
function setTemp() {
clock.style.visibility = "hidden";
timer.style.visibility = "hidden";
temp.style.visibility = "visible";
let tempDisplay = temp.innerHTML;
if (tempDisplay != "MAX: " + maxTemp) {
timerId = setInterval(increaseTemp, 500);
}
knob.style.webkitAnimationPlayState = "paused";
}
// if move away from temp show the clock unless timer is active
function showClock() {
clock.style.visibility = "visible";
timer.style.visibility = "hidden";
temp.style.visibility = "hidden";
// if timer running then show the timer
if (timerRunning == true) {
timer.style.visibility = "visible";
clock.style.visibility = "hidden";
}
clearInterval(timerId);
knob.style.webkitAnimationPlayState = "paused";
}
// when move away from timer show clock if timer not running
function showClock2() {
if (timerLength <= 0) {
clock.style.visibility = "visible";
timer.style.visibility = "hidden";
temp.style.visibility = "hidden";
}
}
// when mouse goes over timer then start the timer countdown and continue in background
function setTimer() {
clock.style.visibility = "hidden";
timer.style.visibility = "visible";
temp.style.visibility = "hidden";
if (timerComplete == false && timerRunning == false) {
knob2.style.webkitAnimationPlayState = "running";
countdown = setInterval(function () {
timerRunning = true;
minutes = parseInt(timerLength / 60, 10);
seconds = parseInt(timerLength % 60, 10);
minutes = minutes < 10 ? "0" + minutes : minutes;
seconds = seconds < 10 ? "0" + seconds : seconds;
timer.innerHTML = minutes + ":" + seconds;
if (--timerLength < 0) {
timer.innerHTML = "DONE!";
knob2.style.webkitAnimationPlayState = "paused";
timerRunning = false;
timerComplete = true;
clearInterval(countdown);
}
}, 1000);
}
}
let timer = document.getElementById("timer");
let temp = document.getElementById("temp");
let knob = document.getElementById("knob");
let knob2 = document.getElementById("knob2");
let timerComplete = false;
let maxTemp = 160;
let tempInc = 10;
let timerLength = 20;
let tempCount = 0;
let timerId, countdownId, countdown;
let timerRunning = false;
// dispays time on display in 24 hour format.
function digitalTime() {
var date = new Date();
var hour = date.getHours();
var min = date.getMinutes();
var sec = date.getSeconds();
hour = checkNumber(hour);
min = checkNumber(min);
sec = checkNumber(sec);
clock.innerText = hour + " : " + min + " : " + sec;
var t = setTimeout(function () {
digitalTime();
}, 1000);
}
// checks if single digit, if so add zero to it
function checkNumber(k) {
result = k < 10 ? "0" + k : k;
return result;
}
// activate the time from the start
digitalTime();
// increments the temperature and stops when reached max
function increaseTemp() {
let displayTemp = temp.innerHTML;
if (displayTemp != "MAX: " + maxTemp) {
knob.style.webkitAnimationPlayState = "running";
let tempNumber = (tempCount += tempInc);
if (tempNumber > maxTemp) {
tempNumber = maxTemp;
}
temp.innerHTML = "TEMP: " + tempNumber;
if (tempNumber == maxTemp) {
temp.innerHTML = "MAX: " + maxTemp;
knob.style.webkitAnimationPlayState = "paused";
}
}
}
// increase the temperature
function setTemp() {
clock.style.visibility = "hidden";
timer.style.visibility = "hidden";
temp.style.visibility = "visible";
let tempDisplay = temp.innerHTML;
if (tempDisplay != "MAX: " + maxTemp) {
timerId = setInterval(increaseTemp, 500);
}
knob.style.webkitAnimationPlayState = "paused";
}
// if move away from temp show the clock unless timer is active
function showClock() {
clock.style.visibility = "visible";
timer.style.visibility = "hidden";
temp.style.visibility = "hidden";
// if timer running then show the timer
if (timerRunning == true) {
timer.style.visibility = "visible";
clock.style.visibility = "hidden";
}
clearInterval(timerId);
knob.style.webkitAnimationPlayState = "paused";
}
// when move away from timer show clock if timer not running
function showClock2() {
if (timerLength <= 0) {
clock.style.visibility = "visible";
timer.style.visibility = "hidden";
temp.style.visibility = "hidden";
}
}
// when mouse goes over timer then start the timer countdown and continue in background
function setTimer() {
clock.style.visibility = "hidden";
timer.style.visibility = "visible";
temp.style.visibility = "hidden";
if (timerComplete == false && timerRunning == false) {
knob2.style.webkitAnimationPlayState = "running";
countdown = setInterval(function () {
timerRunning = true;
minutes = parseInt(timerLength / 60, 10);
seconds = parseInt(timerLength % 60, 10);
minutes = minutes < 10 ? "0" + minutes : minutes;
seconds = seconds < 10 ? "0" + seconds : seconds;
timer.innerHTML = minutes + ":" + seconds;
if (--timerLength < 0) {
timer.innerHTML = "DONE!";
knob2.style.webkitAnimationPlayState = "paused";
timerRunning = false;
timerComplete = true;
clearInterval(countdown);
}
}, 1000);
}
}