Local Weather
How do I make an local weather?
As part of curriculum at www.freecodecamp.com, I am creating a page that will display local weather.. What is a local weather? How do you make a local weather? This script and codes were developed by Kevin on 27 August 2022, Saturday.
Local Weather - Script Codes HTML Codes
<!DOCTYPE html>
<html >
<head> <meta charset="UTF-8"> <title>Local Weather</title> <meta name="viewport" content="width=device-width, initial-scale=1">
<link href='https://fonts.googleapis.com/css?family=Montserrat:700' rel='stylesheet' type='text/css'> <link rel='stylesheet prefetch' href='https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css'>
<link rel='stylesheet prefetch' href='https://cdnjs.cloudflare.com/ajax/libs/weather-icons/2.0.9/css/weather-icons.min.css'> <link rel="stylesheet" href="css/style.css">
</head>
<body> <div class="main-background container-fluid"> <div class = "title-fonts text-center" id = "testBox"></div> <div class = "city-fonts text-center" id="data"></div> <div class = "text-center" id="weatherIcon"></div> <div id = "currentTime"></div> <div class="row"> <div class = "col-xs-12 col-sm-4"> <div class="weather-box center-block"> <div class="title-fonts text-center section-title">Sun Information</div> <div id="sunClock"></div> </div> </div> <div class = "col-xs-12 col-sm-4"> <div class = "weather-box center-block"> <div class ="title-fonts text-center section-title">Temperature <span id = "tempF">F</span> <span id = "tempC">C</span> </div> <div id = "temperature"></div> </div> </div> <div class = "col-xs-12 col-sm-4"> <div class="weather-box center-block"> <div class="title-fonts text-center section-title">Wind</div> <div id = "windSpeed"></div> </div> </div>
</div> <script src='https://cdnjs.cloudflare.com/ajax/libs/jquery/2.2.2/jquery.min.js'></script>
<script src='https://cdnjs.cloudflare.com/ajax/libs/jqueryui/1.11.4/jquery-ui.min.js'></script> <script src="js/index.js"></script>
</body>
</html>
Local Weather - Script Codes CSS Codes
.main-background { background-color: #111111; min-height: 100vh
}
i{ color: #eeeeee; font-size: 40px;
}
#weatherIcon{ padding:20px;
}
.city-fonts{ color: #eeeeee; font-family: Montserrat; font-size: 40px; padding-top: 40px;
}
.title-fonts { color: #eeeeee; font-family: Montserrat; font-size: 30px; padding-top: 40px;
}
#currentTime { padding-bottom: 40px;
}
.weather-fonts { color: #eeeeee; font-family: Montserrat; font-size: 24px;
}
#tempF, #tempC { padding: 0 10px 0 10px;
}
.not_selected_temp{ color: #666666; background-color: #333333;
}
.selected_temp { color: #00ccff; background-color: #333333;
}
.section-title { padding-bottom: 40px;
}
Local Weather - Script Codes JS Codes
$(document).ready(function() { $.ajax({ url: "https://api.wunderground.com/api/18aacec6a6cf0451/geolookup/forecast/astronomy/conditions/q/autoip.json", dataType: "jsonp", success: function(weatherData) { var latitude = weatherData['location']['lat']; var longitude = weatherData['location']['lon']; var city = weatherData['location']['city']; var state = weatherData['location']['state'] var temp_f = weatherData['current_observation']['temp_f']; var temp_c = weatherData['current_observation']['temp_c']; var weather = weatherData['current_observation']['weather']; var windDir = weatherData['current_observation']['wind_dir']; var windSpeed = weatherData['current_observation']['wind_mph']; var windScale = weatherData['current_observation']['wind_string']; var weatherIcon = weatherData['current_observation']['icon']; var sunriseHour = weatherData['sun_phase']['sunrise']['hour']; var sunriseMinute = weatherData['sun_phase']['sunrise']['minute']; var sunsetHour = weatherData['sun_phase']['sunset']['hour']; var sunsetMinute = weatherData['sun_phase']['sunset']['minute']; var currentHour = weatherData['moon_phase']['current_time']['hour']; var currentMinute = weatherData['moon_phase']['current_time']['minute']; var totalSunriseMinutes = Number(sunriseHour) * 60 + Number(sunriseMinute); var totalSunsetMinutes = Number(sunsetHour) * 60 + Number(sunsetMinute); var totalCurrentMinutes = Number(currentHour) * 60 + Number(currentMinute); if (totalSunriseMinutes < totalCurrentMinutes) { totalSunriseMinutes += 1440; } if (totalSunsetMinutes < totalCurrentMinutes) { totalSunsetMinutes += 1440; } var timeTilSunriseMinutes = (totalSunriseMinutes - totalCurrentMinutes) % 60; var timeTilSunriseHours = (totalSunriseMinutes - totalCurrentMinutes - timeTilSunriseMinutes) / 60; var timeTilSunsetMinutes = (totalSunsetMinutes - totalCurrentMinutes) % 60; var timeTilSunsetHours = (totalSunsetMinutes - totalCurrentMinutes - timeTilSunsetMinutes) / 60; if (timeTilSunsetMinutes < 10) { timeTilSunsetMinutes = "0" + timeTilSunsetMinutes; } if (timeTilSunriseMinutes < 10) { timeTilSunriseMinutes = "0" + timeTilSunriseMinutes; } /*$('#testBox').html("<p class = 'weather-fonts text-center'> totalCurrentMinutes: "+ totalCurrentMinutes + "<br>totalSunriseMinutes: " + totalSunriseMinutes + "<br>totalSunsetMinutes: " + totalSunsetMinutes + "<br>timeTilSunriseMinutes: " + timeTilSunriseMinutes + "<br>timeTilSunriseHours: " + timeTilSunriseHours + "<br>timeTilSunsetMinutes: " + timeTilSunsetMinutes + "<br>timeTilSunSetHours: " + timeTilSunsetHours);*/ if (Number(currentHour) < Number(sunsetHour) && Number(currentHour) > Number(sunriseHour)) { var iconTime = "sunny" } else { var iconTime = "clear" } /*This switch is super tedious, but the weather icons do not have mapping for night */ switch (weatherIcon) { case "chanceflurries": var currentWeatherIcon = "snow-wind"; break; case "chancerain": var currentWeatherIcon = "rain"; break; case "chancesleat": var currentWeatherIcon = "sleet"; break; case "chancesnow": var currentWeatherIcon = "snow"; break; case "chancetstorms": var currentWeatherIcon = "thunderstorm"; break; case "clear": var currentWeatherIcon = iconTime; break; case "cloudy": var currentWeatherIcon = "cloudy"; break; case "flurries": var currentWeatherIcon = "snow-wind"; break; case "hazy": var currentWeatherIcon = "haze"; break; case "mostlycloudy": var currentWeatherIcon = "cloudy"; break; case "mostlysunny": var currentWeatherIcon = iconTime; break; case "partlycloudy": var currentWeatherIcon = "cloudy"; break; case "partlysunny": var currentWeatherIcon = iconTime; break; case "rain": var currentWeatherIcon = "showers"; break; case "sleat": var currentWeatherIcon = "sleet"; break; case "snow": var currentWeatherIcon = "snow"; break; case "sunny": var currentWeatherIcon = iconTime; break; case "tstorms": var currentWeatherIcon = "thunderstorm"; break; default: var currentWeatherIcon = iconTime; break; } $('#data').append(city + ', ' + state); $('#currentTime').append("<p class = 'weather-fonts text-center'>" + currentHour + ":" + currentMinute + ", " + weather + "</p>"); if (Number(currentHour) < Number(sunsetHour) && Number(currentHour) > Number(sunriseHour)) { $('#weatherIcon').append("<i class='wi wi-day-" + currentWeatherIcon + "'></i>"); } else { $('#weatherIcon').append("<i class='wi wi-night-" + currentWeatherIcon + "'></i>"); } var sendTempF = function() { $("#temperature").html("<p class = 'weather-fonts text-center'>" + temp_f + " F</p>"); }; var sendTempC = function() { $("#temperature").html("<p class = 'weather-fonts text-center'>" + temp_c + " C</p>"); }; sendTempF(); $("#windSpeed").append("<p class = 'weather-fonts text-center'>" + windSpeed + " Mph from the " + windDir + "</p>") $("#sunClock").append("<p class= 'weather-fonts text-center'>The next sunrise is at " + sunriseHour + ":" + sunriseMinute + "<br>The next sunset is at " + sunsetHour + ":" + sunsetMinute + "</p>") /* $("#sunClock").append("<p class= 'weather-fonts text-center'> Sunrise is at: "+sunriseHour+":"+sunriseMinute+"<br>Sunset is at: "+sunsetHour+":"+sunsetMinute+"<br><br>The next sunrise is in "+timeTilSunriseHours+" hours and "+timeTilSunriseMinutes+" minutes<br>The next sunset is in "+timeTilSunsetHours+" hours and "+timeTilSunsetMinutes+" minutes</p>")*/ $('#tempF').addClass('selected_temp'); $('#tempC').addClass('not_selected_temp'); $('#tempF, #tempC').on('click', function() { $('#tempF, #tempC').toggleClass('selected_temp not_selected_temp'); if ($('#tempF').hasClass('selected_temp')) { sendTempF(); } else { sendTempC(); } }); } });
});
Developer | Kevin |
Username | KevinBruland |
Uploaded | August 27, 2022 |
Rating | 3 |
Size | 3,638 Kb |
Views | 30,360 |
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 |
Canvas Circle Illusion | 3,285 Kb |
Pomodoro Clock | 4,580 Kb |
Simon | 5,318 Kb |
Memory | 4,680 Kb |
Glossy Buttons | 3,228 Kb |
Canvas Optical Illusion | 2,148 Kb |
Canvas Mouse Position Radial Gradient | 2,031 Kb |
Calculator | 3,704 Kb |
Markdown preview | 3,250 Kb |
Canvas Gears | 2,800 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 |
Sinclair Research Computers | MattCowley | 3,068 Kb |
Lightrays v2 | Sinthetyc | 2,903 Kb |
Jstam.com Home Page | Jstam | 10,558 Kb |
SVG Hover Animations | Kjbrum | 10,557 Kb |
Animating characters with jQuery | 042 | 2,776 Kb |
Cartoon Bomb | Tcmulder | 4,929 Kb |
Alter bg opacity on hover... | Chrisboon27 | 2,054 Kb |
SVG Circle Progress | JMChristensen | 3,368 Kb |
Fluid Grid 12 | Alexoliverwd | 2,309 Kb |
Flying Bee | Pwsm50 | 3,711 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!