Skip to content
This repository has been archived by the owner on Oct 26, 2020. It is now read-only.

Nawal week 9 #1024

Open
wants to merge 2 commits into
base: manchester3
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
28 changes: 15 additions & 13 deletions week-9/Homework/mandatory/1-practice/2-code-reading.md
Original file line number Diff line number Diff line change
@@ -1,20 +1,22 @@
# Code reading
// # Code reading

## Question 1
// ## Question 1

Take a look at the following code:
// Take a look at the following code:

```
1 let x = 1;
// ```


1let x = 1;
2 {
3 let x = 2;
4 console.log(x);
5 }
6 console.log(x);
```

Explain why line 4 and line 6 output different numbers.
Explain why line 4 and line 6 output different numbers.

line 4 has a local varible declared inside a local scope. Line 6 only has access only codeto the global scope.
## Question 2

Take a look at the following code:
Expand All @@ -24,12 +26,12 @@ let x = 10

function f1()
{
console.log(x)
console.log(x) // 10
let y = 20
}

console.log(f1())
console.log(y)
console.log(f1()) //undefined - no parameter inside.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good work, the issue is there is no return

console.log(y) // undefined- y is a local scope and not global so value found.
```

What will be the output of this code. Explain your answer in 50 words or less.
Expand All @@ -47,7 +49,7 @@ function f1(val) {
}

f1(x);
console.log(x);
console.log(x); // 9

const y = { x: 9 };

Expand All @@ -57,7 +59,7 @@ function f2(val) {
}

f2(y);
console.log(y);
```
console.log(y); // x : 10 y is an object and returning its value pair
// ```

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good answer, double check passing by value vs by reference


What will be the output of this code. Explain your answer in 50 words or less.
67 changes: 67 additions & 0 deletions week-9/Homework/mandatory/1-practice/app.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
window.addEventListener('load', ()=>{
let long;
let lat;
let temperatureDescription =document.querySelector(".temperature-description");
let temperatureDegree = document.querySelector(".temperature-degrees");
let locationTimezone = document.querySelector(".location-timezone")
let temperatureSection = document.querySelector(".temperature")
let temperatureSpan = document.querySelector(".temperature span")


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


//const api = `http://api.openweathermap.org/data/2.5/forecast?lat=${lat}&lon=${long}&appid=a7850328643c2540185792c17544c7d1&units=metrics`;
//const proxy = " ";
const api = `https://cors-anywhere.herokuapp.com/https://api.darksky.net/forecast/fd9d9c6418c23d94745b836767721ad1/${lat},${long}`;

fetch(api )
.then(response => {
mode: 'no-cors'
return response.json();
})
.then(data => {
console.log(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 celsius

let celsius = (temperature - 32)* (5/9);

//set icon
setIcons(icon, document.querySelector(".icon"))

//change temperature from F to C
degreeSection.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])
}
})

24 changes: 24 additions & 0 deletions week-9/Homework/mandatory/1-practice/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="style.css">
<title>Weather app</title>
</head>
<body>
<div class="location">
<h1 class="location-timezone">Timezones</h1>
<canvas class="icon" width="128" height="128"></canvas>
</div>
<div class="temperature">
<div class="degree-section">
<h2 class="temperature-degrees">34</h2>
<span>F</span>
</div>
<div class="temperature-description">It's friggin cold!</div>
</div>
<script src="skycons.js"></script>
<script src="app.js"></script>
</body>
</html>
Loading