Weather generator
How do I make an weather generator?
What is a weather generator? How do you make a weather generator? This script and codes were developed by Alex Sperellis on 20 December 2022, Tuesday.
Weather generator - Script Codes HTML Codes
<!DOCTYPE html>
<html >
<head> <meta charset="UTF-8"> <title>weather generator</title> <link rel="stylesheet" href="css/style.css">
</head>
<body> <section class='weather'> <img class='weather-icon' alt='Weather'> <button class='weather-temp'></button> <h1><span class='weather-title'></span> in <span class='weather-location'></span></h1> <p>Click temperature to change units</p>
</section> <script src="js/index.js"></script>
</body>
</html>
Weather generator - Script Codes CSS Codes
body {
background: #ff9966; /* fallback for old browsers */
background: -webkit-linear-gradient(to right, #ff5e62, #ff9966); /* Chrome 10-25, Safari 5.1-6 */
background: linear-gradient(to right, #ff5e62, #ff9966); /* W3C, IE 10+/ Edge, Firefox 16+, Chrome 26+, Opera 12+, Safari 7+ */ font-family: 'Helvetica', Arial, sans-serif;
}
.weather { display:flex; flex-direction: column; width: 300px; align-items: center; margin: 0 auto; color: #fff;
}
.weather-location { margin-top: 0; margin-bottom: 5px;
}
.weather-temp { margin-top: 0; margin-bottom: 5px; font-size: 65px; background: none; border: none; color: #fff; cursor: pointer; outline: none;
}
.weather-title { margin-top: 20px; margin-bottom: 5px;
}
.weather-icon { width: 50px; height: 50px;
}
Weather generator - Script Codes JS Codes
function changeTemp() { const tempText = temp.innerHTML; const tempUnit = tempText.slice(tempText.length-1); let tempInt = parseFloat(tempText.slice(0,-1), 10); if(tempUnit.toLowerCase() === 'c') { // convert to f tempInt = (tempInt * 1.8) + 32; temp.innerHTML = Math.round(tempInt * 100) / 100 + 'F'; } else { // convert to c tempInt = (tempInt - 32) / 1.8; temp.innerHTML = Math.round(tempInt * 100) / 100 + 'C'; }
}
function updateWeather(data) { const location = document.querySelector('.weather-location'); const temp = document.querySelector('.weather-temp'); const title = document.querySelector('.weather-title'); const icon = document.querySelector('.weather-icon'); location.innerHTML = data.name + ', ' + data.sys.country; temp.innerHTML = data.main.temp + 'C'; title.innerHTML = data.weather[0].main; icon.setAttribute('src', data.weather[0].icon);
}
function getWeather(lat, long){ return fetch('https://fcc-weather-api.glitch.me/api/current?lat='+lat+'&lon='+long).then((res) => { return res.json().then(json => ({ json, res })); }).then(({ json, res }) => { if(!res.ok) { return Promise.reject(json); } updateWeather(json); });
}
function geo_success(position) { getWeather(position.coords.latitude, position.coords.longitude);
}
function geo_error() { alert("Sorry, no position available.");
}
const temp = document.querySelector('.weather-temp');
const geo_options = { enableHighAccuracy: true, maximumAge : 30000, timeout : 27000
};
const getLocation = navigator.geolocation.watchPosition(geo_success, geo_error, geo_options);
temp.onclick = changeTemp;
Developer | Alex Sperellis |
Username | asperellis |
Uploaded | December 20, 2022 |
Rating | 3 |
Size | 2,614 Kb |
Views | 14,168 |
Find the perfect freelance services for your business! Fiverr's mission is to change how the world works together. Fiverr connects businesses with freelancers offering digital services in 500+ categories. Find Developer!
Name | Size |
Floating Form Labels and Parsley Validation Tests | 4,433 Kb |
Wiki viewer | 4,855 Kb |
Mobile Navigation | 10,631 Kb |
Credit Card Form with Parsley Validation | 8,966 Kb |
Landing Page Html | 3,717 Kb |
Highlights | 1,186 Kb |
Quote generator | 2,325 Kb |
Responsive Modal | 10,524 Kb |
Map infobox | 15,072 Kb |
Window.print test | 1,524 Kb |
Jasper is the AI Content Generator that helps you and your team break through creative blocks to create amazing, original content 10X faster. Discover all the ways the Jasper AI Content Platform can help streamline your creative workflows. Start For Free!
Name | Username | Size |
Ghost Buttons with CSS3 | Mithicher | 2,509 Kb |
Toolbar | Onsen | 5,414 Kb |
Simple Linear Regression with Editable Table | Melatonind | 3,264 Kb |
Compare resources on mobile sites | Gyusza | 3,226 Kb |
Bloomberg Style Link Hover | Gil-- | 1,609 Kb |
RWD Conversion Practice | Jxqr97 | 2,743 Kb |
Spiralator 9000 | AdmiralPotato | 4,671 Kb |
Sticky menu on scroll | Senff | 2,869 Kb |
Multiple jCarousel | Pafnuty | 2,461 Kb |
Css3 slide | Nakome | 3,190 Kb |
Surf anonymously, prevent hackers from acquiring your IP address, send anonymous email, and encrypt your Internet connection. High speed, ultra secure, and easy to use. Instant setup. Hide Your IP Now!