37 lines
1.0 KiB
JavaScript
37 lines
1.0 KiB
JavaScript
|
const button = document.querySelector("button")
|
||
|
const input = document.getElementById("kezdoertek")
|
||
|
const p = document.querySelector("p")
|
||
|
let myInterval
|
||
|
|
||
|
button.addEventListener("click", () => {
|
||
|
let kezdoertek = Number(input.value)
|
||
|
myInterval = setInterval(() => {
|
||
|
let myPromise = new Promise((resolve, reject) => {
|
||
|
if (kezdoertek >= 0) {
|
||
|
resolve(`Visszaszámlálás: ${kezdoertek}`)
|
||
|
kezdoertek--
|
||
|
} else {
|
||
|
reject("Boldog Új Évet!")
|
||
|
clearInterval(myInterval)
|
||
|
}
|
||
|
})
|
||
|
|
||
|
myPromise
|
||
|
.then(result => {
|
||
|
p.innerHTML = result
|
||
|
})
|
||
|
.catch(error => {
|
||
|
p.innerHTML = error
|
||
|
})
|
||
|
}, 1000)
|
||
|
})
|
||
|
|
||
|
fetch('https://name-day.onrender.com/', {
|
||
|
method: 'GET',
|
||
|
headers: {
|
||
|
'Content-Type': 'application/json',
|
||
|
},
|
||
|
})
|
||
|
.then(response => response.json())
|
||
|
.then(data => console.log(data))
|
||
|
.catch((error) => console.error('Error:', error));
|