Weather App

Developer
Size
2,824 Kb
Views
12,144

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 Previews

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();
Weather App - Script Codes
Weather App - Script Codes
Home Page Home
Developer Kalene
Username kalenenc
Uploaded November 28, 2022
Rating 3
Size 2,824 Kb
Views 12,144
Do you need developer help for Weather App?

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!

Kalene (kalenenc) Script Codes
Create amazing sales emails with AI!

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!