<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<div class="background-wrapper">
<img class="background" src="https://picsum.photos/300/100?1"/>
</div>
</body>
</html>
let getImg = document.querySelector('.background');
let backgroundArrayImg = [
'https://picsum.photos/300/100?1', 'https://picsum.photos/300/100?2', 'https://picsum.photos/300/100?3'
];
let count = 1;
getImg.addEventListener('click', () => {
if(count === backgroundArrayImg.length){
count = 0;
}
else{
getImg.src = backgroundArrayImg[count];
count++;
}
})
let bgIndex = 0;
appBackground.backgroundParrent.addEventListener('click', () => {
const url = backgroundArrayImg[(++bgIndex) % backgroundArrayImg.length];
document.querySelector('body').style.backgroundImage = `url(${url})`;
});
second
,const timerObject = {
DATE: new Date(),
listDATE: {
get second() {
return new Date().getSeconds();
},
},
};
// читать, как обычно
console.log( timerObject.listDATE.second );
// через секунду
setTimeout(() => console.log( timerObject.listDATE.second ), 1000); // на 1 больше
const timerObject = {
DATE: new Date(),
listDATE: {
second: () => new Date().getSeconds(),
},
};
// использование
console.log( timerObject.listDATE.second() );
const electricDate = document.querySelector(".electronic__date");
const electricTime = document.querySelector(".electronic__clock");
setInterval(checkDateAndTime, 1000);
function checkAddZero(num) {
return num < 10 ? "0" + num : num
}
function checkDateAndTime() {
const DATE = new Date();
const week = ["ВС", "ПОН", "ВТ", "СР", "ЧТ", "ПТ", "СУБ"];
let year = DATE.getFullYear();
let month = checkAddZero(DATE.getMonth() + 1);
let day = checkAddZero(DATE.getDate());
let hour = checkAddZero(DATE.getHours());
let minute = checkAddZero(DATE.getMinutes());
let second = checkAddZero(DATE.getSeconds());
electricDate.innerHTML = year + "-" + month + "-" + day + " " + week[DATE.getDay()];
electricTime.innerHTML = hour + ":" + minute + ":" + second;
}
let d = new Date;
let offset = d.getTimezoneOffset() * 60*1000
d.setTime(d.getTime() - offset)
let matches = d.toISOString().match(/^(.*?)T(.*?)\./)
console.log(matches[1], matches[2]);
console.log(d.toLocaleDateString(undefined, {weekday: 'short'}));
(язык можно прибить гвоздями, а так будет на языке пользователя)