Weather App
How do I make an weather app?
What is a weather app? How do you make a weather app? This script and codes were developed by Kalene on 28 November 2022, Monday.
Weather App - Script Codes HTML Codes
<!DOCTYPE html>
<html >
<head> <meta charset="UTF-8"> <title>Weather App</title> <link rel="stylesheet" href="css/style.css">
</head>
<body> <main> <h1>Kalene's Weather App</h1> <h2 class="city"></h2> <h3 class="degrees"></h3> <button>to <span class="buttonSpan"><span></button> <h3 class="description"></h3> <div class="icon"> <img /> </div>
</main> <script src="js/index.js"></script>
</body>
</html>
Weather App - Script Codes CSS Codes
*,
*:before,
*:after { padding: 0px; margin: 0px;
}
:root { --darkPurple: #5D4E60; --plum: #826C7F; --purple: #A88FAC; --lightPurple: #D4B2D8; --lightestPurple: #EFCEFA; --gutter: 20px; --otherGutter: 15px; --blue: #034078; --teal: #1282A2; --darkBlue: #001F54; --pink: #EA638C; --darkBlue: #001F54;
}
html { height: 100%;
}
body { font-family: 'Lato', sans-serif; background: linear-gradient(var(--teal), var(--blue)); color: var(--darkBlue); font-size: 1.5em;
}
main { width: 80%; margin: 1em auto 0 auto; text-align: center; background: rgba(255, 255, 255, 0.81); -webkit-box-shadow: 10px 10px 33px -10px rgba(0, 0, 0, 0.75); -moz-box-shadow: 10px 10px 33px -10px rgba(0, 0, 0, 0.75); box-shadow: 10px 10px 33px -10px rgba(0, 0, 0, 0.75); border-radius: 20px;
}
button { background: var(--pink); border: none; border-radius: 10px; padding: 10px; margin-bottom: var(--otherGutter); font-size: 15px; font-weight: bold; -webkit-box-shadow: 10px 10px 33px -10px rgba(0, 0, 0, 0.75); -moz-box-shadow: 10px 10px 33px -10px rgba(0, 0, 0, 0.75); box-shadow: 10px 10px 33px -10px rgba(0, 0, 0, 0.75); transition: all 0.2s ease-in-out;
}
button:hover { background: #b84c6d;
}
h1 { margin-bottom: var(--otherGutter); padding-top: var(--otherGutter);
}
h3 { margin-bottom: var(--otherGutter);
}
.city { color: #883d95; padding-bottom: var(--otherGutter);
}
@media only screen and (max-width:500px) { main { width: 95%; }
}
Weather App - Script Codes JS Codes
var city = document.querySelector('.city');
var degrees = document.querySelector('.degrees');
var description = document.querySelector('.description');
var icon = document.querySelector('.icon');
var button = document.querySelector('button');
var toggleDegress = 'imperial';
var ending = "°F"
var buttonEnding = 'Celsius';
var buttonSpan = document.querySelector('.buttonSpan');
var image = document.querySelector('img');
buttonSpan.innerHTML = buttonEnding;
function renderInfo() { var ourRequest = new XMLHttpRequest(); ourRequest.open('GET', 'http://api.openweathermap.org/data/2.5/weather?id=5206379&units=' + toggleDegress + '&APPID=2380e8d9f38054235ac2a0b92ec28479', true); ourRequest.onload = function() { var response = JSON.parse(ourRequest.responseText); city.innerHTML = response.name; determinePicture(response.weather[0].main); description.innerHTML = response.weather[0].main; degrees.innerHTML = response.main.temp + ending; } ourRequest.send();
}
function newAttribute(srcLoc) { image.setAttribute("src", srcLoc);
}
function determinePicture(description) { if (description.toLowerCase() === "clear") { newAttribute('http://openweathermap.org/img/w/01d.png'); } else if (description.toLowerCase() === 'clouds') { newAttribute('http://openweathermap.org/img/w/03d.png'); } else if (description.toLowerCase() === 'rain') { newAttribute('http://openweathermap.org/img/w/10d.png'); } else if (description.toLowerCase() === 'storm') { newAttribute('http://openweathermap.org/img/w/11d.png'); } else if (description.toLowerCase() === 'snow') { newAttribute('http://openweathermap.org/img/w/13d.png'); } else if (description.toLowerCase() === 'mist') { newAttribute('http://openweathermap.org/img/w/50d.png'); } else if (description.toLowerCase() === 'extreme') { newAttribute('http://openweathermap.org/img/w/11d.png'); }
}
function changeDegrees() { if (toggleDegress === 'imperial') { toggleDegress = 'metric'; ending = "°C"; buttonEnding = 'Fahrenheit'; buttonSpan.innerHTML = buttonEnding; } else { toggleDegress = 'imperial'; ending = "°F"; buttonEnding = 'Celsius'; buttonSpan.innerHTML = buttonEnding; }
}
button.addEventListener('click', function() { changeDegrees(); var degreesRequest = new XMLHttpRequest(); degreesRequest.open('GET', 'http://api.openweathermap.org/data/2.5/weather?id=5206379&units=' + toggleDegress + '&APPID=2380e8d9f38054235ac2a0b92ec28479', true); degreesRequest.onload = function() { var degreesResponse = JSON.parse(degreesRequest.responseText); degrees.innerHTML = degreesResponse.main.temp + ending; } degreesRequest.send();
});
renderInfo();
Developer | Kalene |
Username | kalenenc |
Uploaded | November 28, 2022 |
Rating | 3 |
Size | 2,824 Kb |
Views | 12,144 |
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 |
Simple CSS Grid Navbar | 3,292 Kb |
Turn.js | 1,812 Kb |
Draggable Vanilla JS - No jQuery UI | 3,656 Kb |
Roman Numeral Converter | 2,994 Kb |
Money Calculator | 1,154 Kb |
Just Enough jQuery to Get By - React Part | 2,916 Kb |
JQuery Advanced Filters | 1,791 Kb |
Quote Generator | 3,716 Kb |
SVG Practice | 1,411 Kb |
Idk | 2,623 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 |
A Pen by Jason Kinney | Jason-kinney | 1,980 Kb |
Css or Czz.. | Judag | 4,111 Kb |
Pattern lab logo | TimPietrusky | 3,666 Kb |
Twitch | SarahDunlap | 2,937 Kb |
Segments mouse following | Nosir | 2,909 Kb |
Tail rose iris lined | Kbrtrm | 1,846 Kb |
Two column of responsive height | Fixie | 2,908 Kb |
IbrahimJabbari-Effect14 | Ibrahimjabbari | 1,919 Kb |
Funny menu | AxeLVaisper | 4,671 Kb |
BlueBox Fork | Huskynation | 12,675 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!