Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Complete - Peter #6

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
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
74 changes: 51 additions & 23 deletions coding-exercises/app.js
Original file line number Diff line number Diff line change
@@ -1,32 +1,60 @@
console.log("javaScript is Connected.");

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.
*/

alert("Your Location is required.")

const secretKey = "5e70c6f2688e6b60969e6693bbfff0c7"
const proxy = "https://cors-anywhere.herokuapp.com/"

if (navigator.geolocation) {
navigator.geolocation.getCurrentPosition(position => {
console.log('My General Position:', position);
const long = position.coords.longitude;
const lat = position.coords.latitude;

fetch(`${proxy}https://api.darksky.net/forecast/${secretKey}/${lat},${long}`)
// fetch(`${proxy}https://api.darksky.net/forecast/5e70c6f2688e6b60969e6693bbfff0c7/37.8267,-122.4233`)
.then((response) => response.json())
.then((json) => {

const cityPlaceHolder = document.getElementById("cityPlaceHolder");
const degreesPlaceHolder = document.getElementById("degreesPlaceHolder");
const scalePlaceHolder = document.getElementById("scalePlaceHolder");
const descriptionPlaceHolder = document.getElementById("descriptionPlaceHolder");
const canvas = document.getElementById("canvas");
console.log(json);

cityPlaceHolder.innerText = json.timezone.substring(json.timezone.lastIndexOf("/") + 1).replace(/[_]/g, " ");
degreesPlaceHolder.innerText = Math.floor(json.currently.temperature);
descriptionPlaceHolder.innerText = `${json.currently.summary} \n ${json.hourly.summary}`;
setIcons(json.currently.icon)

/* TODO: Continue your fetch request to set the DOM Elements for
* temperature, description/summary, and timezone.
* Make sure to include error handling.
*/

/*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.
*/
const slider = document.getElementById("slider");

slider.addEventListener("change", (e) => {
if (!slider.checked) {
scalePlaceHolder.innerText = "C"
degreesPlaceHolder.innerText = Math.floor((json.currently.temperature - 32) * (5 / 9))
}
if (slider.checked) {
scalePlaceHolder.innerText = "F"
degreesPlaceHolder.innerText = Math.floor(json.currently.temperature);
}
})
})
.catch(error => {
alert("Weather not found.");
console.warn(error);
})
});
}

/**
* TODO: Code out the remainder of `setIcons`function.
*/
const setIcons = () => {};
});


const setIcons = (icon) => {
const skycons = new Skycons({"color": "pink"});
skycons.add(canvas, icon);
skycons.play();
console.log(icon)
}


20 changes: 10 additions & 10 deletions coding-exercises/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,23 +8,23 @@
</head>
<body>
<div class="location">
<!-- TODO: give this h1 a class-->
<h1>PLACEHOLDER: New York</h1>
<!-- TODO: give this canvas element a class. This element will hold an animated icon-->
<canvas />
<h1 id="cityPlaceHolder">Your City</h1>
<canvas id="canvas" width="128" height="128"/>
</div>
<div class="temperature">
<div class="degree-section">
<!-- TODO: give this h2 a class-->
<h2>PLACEHOLDER: 32</h2>
<!-- TODO: give this span a class-->
<span>PLACHOLDER: F</span>
<h2 id="degreesPlaceHolder">32</h2>
<span id="scalePlaceHolder">F</span>
</div>
<!-- TODO: give this div a class-->
<div>PLACEHOLDER Description: Snowing</div>
<div id="descriptionPlaceHolder">PLACEHOLDER Description: Snowing</div>
<label class="switch">
<input id="slider" type="checkbox" checked>
<span class="slider round"></span>
</label>
</div>

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