FreeCodeCamp - Local Weather App

Developer
Size
3,093 Kb
Views
16,192

How do I make an freecodecamp - local weather app?

What is a freecodecamp - local weather app? How do you make a freecodecamp - local weather app? This script and codes were developed by Jason Thomas on 14 September 2022, Wednesday.

FreeCodeCamp - Local Weather App Previews

FreeCodeCamp - Local Weather App - Script Codes HTML Codes

<!DOCTYPE html>
<html >
<head> <meta charset="UTF-8"> <title>freeCodeCamp - Local Weather App</title> <link rel='stylesheet prefetch' href='https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/4.0.0-alpha.6/css/bootstrap.min.css'>
<link rel='stylesheet prefetch' href='https://erikflowers.github.io/weather-icons/css/weather-icons.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="container"> <div id="temp-data" class="text-center"> <h2 class="display-4" id="city_name"></h2> <h2 class="display-4" id="wea_name"></h2> <p id="cloud"> </p> <p id="temper"> </p> <p id="highLow"> </p> </div>
</div> <script src='https://cdnjs.cloudflare.com/ajax/libs/jquery/3.1.1/jquery.min.js'></script> <script src="js/index.js"></script>
</body>
</html>

FreeCodeCamp - Local Weather App - Script Codes CSS Codes

body { background-image:url(https://dl.dropboxusercontent.com/s/kitaidk2kngujoy/weather.png?dl=0); padding-top:20px;
}
@media (min-width: 500px) { .container{ max-width: 500px; }
}
.container{ background: rgba(247,247,247, .6); color: #4d4d4d; padding: 10px; border-style: dashed; border-width: 1px;
}
#min_temp { float:left;
}
#wea_name { color:#c6011f;
}
#cloud { font-size:3.4em;
}
#tempCel, #tempFar { font-size:3.4em; vertical-align:text-top; line-height:80%;
}
#bt2 { color:blue; padding:0px; border-style: none; background-color:transparent;
}
#bt2:disabled { color:#4d4d4d;
}
#bt1 { color:blue; padding:0px; border-style: none; background-color:transparent;
}
#bt1:disabled { color:#4d4d4d;
}
#cloud, #temper, #highLow { width:100%; display:block;
}
#butDiv {
}

FreeCodeCamp - Local Weather App - Script Codes JS Codes

/*some of the code below was originally writtern by Arijit Layek. https://codepen.io/alayek/pen/xwPzWb */
document.addEventListener( "DOMContentLoaded", function() { var $displayCity = $("#temp-data"); var $cityName = $("#city_name"); var $weatherName = $("#wea_name"); var $cloudDiv = $("#cloud"); //get geo location var geoUrl = "https://freegeoip.net/json/"; console.log("geoUrl: " + geoUrl); $.getJSON(geoUrl, function(data) { geoCity = data.city; console.log("geoCity: " + geoCity); var tempUrl = "https://query.yahooapis.com/v1/public/yql?q=select * from weather.forecast where woeid in (select woeid from geo.places(1) where text='" + geoCity + "') and u='c'&format=json"; $.getJSON(tempUrl, function(data) { var resultArr = []; for (var x in data.query.results.channel) { if (window.CP.shouldStopExecution(1)) { break; } resultArr.push([x, data.query.results.channel[x]]); } window.CP.exitedLoop(1); //weather icons var icon = '<i class="wi wi-yahoo-' + data.query.results.channel.item.condition.code + '"></i>'; //add text from apis to HTML $cityName.append( data.query.results.channel.location.city + ", " + data.query.results.channel.location.country ); $weatherName.append(data.query.results.channel.item.condition.text); $cloudDiv.append(icon); var $tempCel = '<span id="tempCel">' + Math.round( data.query.results.channel.item.condition.temp ) + '</span>'; var $tempFar = '<span id="tempFar">' + Math.round( data.query.results.channel.item.condition.temp * 9 / 5 + 32 ) + '</span>';
/*Add the celcius and fahrenheit buttons*/ $("#temper").append($tempCel + '<span id="butDiv"><button id="bt1" disabled="disabled">&#8451</button> | <button id="bt2">&#8457</button></span>' );
/*the buttons' functions are added*/ $("#bt1").click(function() { $(this).attr("disabled", "disabled"); $("#tempFar").remove(); $("#temper").prepend($tempCel); $("#bt2").removeAttr("disabled"); }); $("#bt2").click(function() { $(this).attr("disabled", "disabled"); $("#tempCel").remove(); $("#temper").prepend($tempFar); $("#bt1").removeAttr("disabled"); }); }); }); }, false
);
/*To do:
- Add highs and lows
- add forcast throughout the week
*/
FreeCodeCamp - Local Weather App - Script Codes
FreeCodeCamp - Local Weather App - Script Codes
Home Page Home
Developer Jason Thomas
Username samoht513
Uploaded September 14, 2022
Rating 3
Size 3,093 Kb
Views 16,192
Do you need developer help for FreeCodeCamp - Local 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!

Jason Thomas (samoht513) Script Codes
Create amazing web content 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!