Skip to content
This repository was archived by the owner on Aug 5, 2021. It is now read-only.

Dan carter week 3 #47

Open
wants to merge 3 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
9 changes: 9 additions & 0 deletions week-3/Homework/mandatory/1-practice/2-code-reading.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ Take a look at the following code:

Explain why line 4 and line 6 output different numbers.

on line 4, x is read from the variable on line 3 as it is within block scope and will reference the closest variable. whereas on line 6 x is read from the global variable on line one, as the variable on line 3 is not available outside of the block scope

## Question 2

Take a look at the following code:
Expand All @@ -34,6 +36,10 @@ console.log(y)

What will be the output of this code. Explain your answer in 50 words or less.

when f1 is called x = 10 (global variable),
console.log(f1()) will be undefined as there is no return from the function
console.log(y) will log nothing as Y is only available within the scope of function f1

## Question 3

Take a look at the following code:
Expand Down Expand Up @@ -61,3 +67,6 @@ console.log(y);
```

What will be the output of this code. Explain your answer in 50 words or less.
x is assigned to a constant and can therefore not be changed, it will still be 9 after running function

whereas with the object what is inside can be changed even tho const is used. so the value of x within the object can increase to x:10 using function f2
59 changes: 59 additions & 0 deletions week-3/Homework/mandatory/1-practice/app.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
window.addEventListener("load", () => {
let long;
let lat;
let temperatureDescription = document.querySelector(".temperature-description");
let temperatureDegree = document.querySelector(".temperature-degree");
let locationTimezone = document.querySelector(".location-timezone");
let temperatureSection = document.querySelector(".temperature");
const temperatureSpan = document.querySelector(".temperature span");

if(navigator.geolocation){
navigator.geolocation.getCurrentPosition(position => {
long = position.coords.longitude;
lat = position.coords.latitude;

const proxy = "https://cors-anywhere.herokuapp.com/";
const api = `${proxy}https://api.darksky.net/forecast/fd9d9c6418c23d94745b836767721ad1/${lat},${long}`;

fetch(api)
.then(response => {
return response.json();
})
.then(data => {
const {temperature, summary, icon} = data.currently;
// set DOM elements from the API
temperatureDegree.textContent = temperature;
temperatureDescription.textContent = summary;
locationTimezone.textContent = data.timezone;
// formula for celcius
let celsius = (temperature-32) * (5/9) ;
// set icon
setIcons(icon, document.querySelector(".icon"));

// change temp C/F
temperatureSection.addEventListener("click", () => {
if(temperatureSpan.textContent === "F") {
temperatureSpan.textContent = "C";
temperatureDegree.textContent = Math.floor(celsius);
} else{
temperatureSpan.textContent = "F";
temperatureDegree.textContent = temperature;
}
})
});
});


}
function setIcons(icon, iconID){
const skycons = new Skycons({color: "white"});
const currentIcon = icon.replace(/-/g, "_").toUpperCase();
skycons.play();
return skycons.set(iconID, skycons[currentIcon]);
}

// }else{
// let h1 = document.getElementsByTagName("h1");
// h1.textContent = "hey dis is not working cause reasons!"
// }
});
29 changes: 29 additions & 0 deletions week-3/Homework/mandatory/1-practice/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<!DOCTYPE html>
<!--[if lt IE 7]> <html class="no-js lt-ie9 lt-ie8 lt-ie7"> <![endif]-->
<!--[if IE 7]> <html class="no-js lt-ie9 lt-ie8"> <![endif]-->
<!--[if IE 8]> <html class="no-js lt-ie9"> <![endif]-->
<!--[if gt IE 8]><!--> <html class="no-js"> <!--<![endif]-->
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<title>Weather</title>
<meta name="description" content="">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="style.css">
</head>
<body>
<div class="location">
<h1 class="location-timezone">Timezone</h1>
<canvas class="icon" width="128" height="128"></canvas>
</div>
<div class="temperature">
<div class="degree-section">
<h2 class="temperature-degree">34</h2>
<span>F</span>
</div>
<div class="temperature-description">it's friggen cold!</div>
</div>
<script src="skycons.js"></script>
<script src="app.js"></script>
</body>
</html>
Loading