CODE:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Check Weather</title>
<style>
body {
margin: 0;
height: 100vh;
display: flex;
justify-content: center;
align-items: center;
background: linear-gradient(135deg, #0f172a, #1e3a8a, #38bdf8);
font-family: Arial, sans-serif;
}
#container {
width: 400px;
font-family: Verdana, Geneva, Tahoma, sans-serif;
background: rgba(255, 255, 255, 0.10);
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
padding: 30px;
margin: auto;
gap: 20px;
backdrop-filter: blur(10px);
border-radius: 20px;
box-shadow: 0 8px 25px rgba(0, 0, 0, 0.3);
background-size: cover;
background-position: center;
background-repeat: no-repeat;
color: white;
text-align: center;
}
#inputbox {
width: 50%;
height: 40px;
border: none;
/* border-radius:25px; */
padding: 10px;
font-size: x-large;
outline: none;
background: rgba(255, 255, 255, 0.25);
color: white;
}
#inputbox::placeholder {
color: #e2e8f0;
}
h3 {
width: 150px;
text-align: center;
margin: 0;
color: black;
font-size: larger;
font-weight: 900;
}
button {
padding: 15px;
width: 150px;
border-radius: 25px;
border: none;
box-shadow: gray 0 10px 10px 0;
font-size: 15px;
background: #38bff8d9;
color: white;
}
button:hover {
background: #0ea5e9;
transform: scale(1.05);
}
</style>
</head>
<body>
<div id="container">
<input id="inputbox" type="text" placeholder="Enter the City">
<button onclick="checkWeather()">Check Weather</button>
<h3 id="temp"></h3>
<h3 id="maxTemp"></h3>
<h3 id="minTemp"></h3>
<!-- <img id="tempImg" style="width: 300px;" > -->
</div>
<script>
async function checkWeather() {
const city = document.getElementById("inputbox").value;
const apiKey = "e68ce0c444414138fbe7040035b317b4";
const res = await fetch(`https://api.openweathermap.org/data/2.5/weather?q=${city}&appid=${apiKey}&units=metric`)
const data = await res.json();
const container = document.getElementById("container");
const temp = document.getElementById("temp");
const maxTemp = document.getElementById("maxTemp");
const minTemp = document.getElementById("minTemp");
// const tempImg = document.getElementById("tempImg");
const currentTemp = data.main.temp;
temp.innerText = `Temperature Today in ${city} : ${data.main.temp} °C`;
maxTemp.innerText = `Max-Temperature Today in ${city} : ${data.main.temp_max} °C`;
minTemp.innerText = `Min-Temperature Today in ${city} : ${data.main.temp_min} °C`;
if (currentTemp > 28) {
container.style.backgroundImage = "url(https://www.shutterstock.com/shutterstock/photos/384381070/display_1500/stock-vector-hot-summer-384381070.jpg)"
}
else {
container.style.backgroundImage = "url(https://thumbs.dreamstime.com/b/freezing-boy-winter-cold-cartoon-vector-shivering-young-standing-snowman-illustration-103588415.jpg)"
}
inputbox.value = "";
}
</script>
</body>
</html>
OUTPUT:



Top comments (0)