Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
73 changes: 72 additions & 1 deletion coding-exercises/app.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,18 @@
window.addEventListener('load', () => {

/**
* TODO : Create your 5 variables to get elements
* based on the classes you created in the `index.html`.
*
* Define your variables below this comment.
*/

const newYork = document.getElementsByClassName('new-york')[0];
const canvas = document.getElementsByClassName('animated-icon');
const placeholder = document.getElementsByClassName('placeholder-32')[0];
const span = document.getElementsByClassName('placeholder-F')[0];
const div = document.getElementsByClassName('description')[0];


if (navigator.geolocation) {
navigator.geolocation.getCurrentPosition(position => {
Expand All @@ -16,8 +24,43 @@ window.addEventListener('load', () => {
* temperature, description/summary, and timezone.
* Make sure to include error handling.
*/
const getApiInfo = async(lat,lon) =>{
const apiKey = '065ad3fe15434cfea6d6c1092979d8ba'
const getData = await requestMethod('GET',`https://cors-anywhere.herokuapp.com/https://cors-anywhere.herokuapp.com/https://api.darksky.net/forecast/${apiKey}/${lat},${lon}`)
const timezone = getData.timezone
const temperature = getData.currently.temperature
const summary = getData.currently.summary
const description = getData.minutely.summary
const icon = getData.currently.icon


newYork.innerHTML = `Location: ${timezone}`
placeholder.innerHTML = `Summary : ${summary}`
span.innerHTML = `Temperature: ${temperature}° F`
div.innerHTML = `Description : ${description}`

setIcons('icon1',icon)
span.addEventListener('click',(e)=>{
const convert = `${Math.floor(temperature - 32) * (5 / 9)}`
const fahreinheit = `Temperature: ${temperature}° F`
const celcius = Number.parseFloat(convert).toFixed()

if(e.target.innerHTML === fahreinheit){
e.target.innerHTML = `${celcius}° C`
}else{
e.target.innerHTML = fahreinheit

}
})
}

getApiInfo(lat,long)




/*TODO: Set the weather icon */


/**TODO: Add an event listener that toggles between Fahrenheit and Celcius
* when a user clicks on the current temperature section.
Expand All @@ -28,5 +71,33 @@ window.addEventListener('load', () => {
/**
* TODO: Code out the remainder of `setIcons`function.
*/
const setIcons = () => {};
const setIcons = (icon,iconID) => {
const skycons = new Skycons()
skycons.add(document.getElementById('icon1') ,iconID)
skycons.play()
};
});

window.alert('Please Allow Location if your are using this weather app. Thank You !')

const requestMethod = (method, url , data) => {
return fetch(url, {
method: method,
body: JSON.stringify(data),
headers: data ? {'Content-Type': 'application/json'} : {},
mode: 'cors'
})
.then(handleError)
.then(response => response.json())
.catch(err => console.log('Error'))
}

const handleError = (response) => {
if (!response.ok) {
throw Error(`${response.statusText} - ${response.url}`);
}
return response;
};



12 changes: 7 additions & 5 deletions coding-exercises/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,22 +9,24 @@
<body>
<div class="location">
<!-- TODO: give this h1 a class-->
<h1>PLACEHOLDER: New York</h1>
<h1 class="new-york">PLACEHOLDER: New York</h1>
<!-- TODO: give this canvas element a class. This element will hold an animated icon-->
<canvas />
<canvas id = 'icon1' class ="animated-icon" width= '128' height='128'/>
</div>
<div class="temperature">
<div class="degree-section">
<!-- TODO: give this h2 a class-->
<h2>PLACEHOLDER: 32</h2>
<h2 class = "placeholder-32">PLACEHOLDER: 32</h2>
<!-- TODO: give this span a class-->
<span>PLACHOLDER: F</span>
<span class="placeholder-F">PLACHOLDER: F</span>
</div>
<!-- TODO: give this div a class-->
<div>PLACEHOLDER Description: Snowing</div>
<div class = "description">PLACEHOLDER Description: Snowing</div>
</div>

<!-- TODO: During the appropriate step in this problem set, place the skycon script here-->
<script src="skycons.js"></script>
<script src="app.js"></script>

</body>
</html>
Loading