What I want to do is I want to make a prompt question if I want to continue(after temp result) or not if not then quit the page BUTTT whenever I put prompt or alert, they appear first instead of the value of the temperature.
const result = document.querySelector(".result") /// button
const change = document.querySelector(".change") /// button
const screen = document.querySelector(".ctF") //h1
const tscreen = document.querySelector(".screen") ///h1
const dta = [{
index: 1,
message: "Celcius to Fahrenheit"
}, {
index: 2,
message: "Fahrenheit to Celcius"
}]
let num = 0
let iV = 1
change.addEventListener("click", () => {
num++
if (num > dta.length - 1) {
num = 0
}
t(num)
})
function t(ss) {
let item = dta[ss]
let message = item.message
let index = item.index
iV = index
tscreen.innerHTML = message
screen.innerHTML = "Temperature"
}
result.addEventListener("click", changeTemp)
function changeTemp() {
const value = document.querySelector(".input").value ///input
let numbaW = 1
let numbaT = 2
if (numbaW == iV) {
let cetFa = value * (1.8) + 32
screen.innerHTML = Math.round(cetFa) + "°F"
window.addEventListener("message")
} else if (numbaT == iV) {
let fatCe = ((value - 32) * 5) / 9
screen.innerHTML = Math.round(fatCe) + "°C"
}
}
prompt and alert are both halting the JavaScript event loop.
This means as long as the user does not click on "ok" no DOM modifications will be processed.
The solution will be to prompt the user after a timeout.
Ususally
setTimeout(() => {
let value = prompt("What's the value?");
alert(`Value: ${value}`);
});
should do the trick for you.