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

shahd-week-9 #1029

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

Explain why line 4 and line 6 output different numbers.

line 4 log x=2 as it's been defined as a local variable inside the curly brakets, line 6 log x=1 for the global variable that has been defiend in line 1
Copy link
Member

Choose a reason for hiding this comment

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

Correct! :)

## Question 2

Take a look at the following code:
Expand All @@ -33,6 +33,7 @@ console.log(y)
```

What will be the output of this code. Explain your answer in 50 words or less.
for the first log in line 27 the output should be 10 for the global variable x, line 31 output will be undefiend the function call is empty no thing has been passed to the function to process, line 32 log undefined since y has been defiend locally inside f1
Copy link
Member

Choose a reason for hiding this comment

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

Close :)

Line 31 output will be undefined because nothing is being returned from the function.
Line 32 will give a "ReferenceError: y is not defined"


## Question 3

Expand All @@ -46,18 +47,18 @@ function f1(val) {
return val;
}

f1(x);
console.log(x);
f1(x); this line will pass x value(10) to the function the out put for it will be 10 and it's going to be returned and not logged to the console.
console.log(x); this line will log 9 the value of the global variable x;

const y = { x: 9 };
const y = { x: 9 }; we have the object y

function f2(val) {
val.x = val.x + 1;
return val;
}

f2(y);
console.log(y);
f2(y); the output for this line should be 10 and the value is returned and not logged to the console;
console.log(y); it will log the object y ===> {x:9}
```
Copy link
Member

Choose a reason for hiding this comment

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

Both correct :)


What will be the output of this code. Explain your answer in 50 words or less.
27 changes: 27 additions & 0 deletions week-9/Homework/mandatory/1-practice/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@

<!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>Wheather app</title>
</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">0.0</h2>
<span>F°</span>
</div>
<div class="temperatur-description">Status</div>
</div>


<script src="script2.js"></script>
<script src="script.js"></script>
</body>
</html>
52 changes: 52 additions & 0 deletions week-9/Homework/mandatory/1-practice/script.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
window.addEventListener('load', ()=> {
let long;
let lat;
let temperatureDescription = document.querySelector('.temperatur-description')
let temperatureDegree = document.querySelector('.temperature-degree')
let locationTimezone = document.querySelector('.location-timezone')
let temperatureSection = document.querySelector('.temperature')
let temperaturSpan = document.querySelector('.temperature span')

if(navigator.geolocation){
navigator.geolocation.getCurrentPosition(positon => {
long = positon.coords.longitude
lat =positon.coords.latitude
const proxy = " https://cors-anywhere.herokuapp.com/"
const api = `${proxy}https://api.darksky.net/forecast/fd9d9c6418c23d94745b836767721ad1/${lat},${long}`

fetch(api)
.then(data => data.json())
.then(data=> {
console.log(data)
const {temperature, summary, icon} = data.currently
//Set DOM Elements form the api
temperatureDegree.textContent = temperature
temperatureDescription.textContent = summary
locationTimezone.textContent = data.timezone

//formula for celsius
let celsius = (temperature - 32) * (5/9)
//Set Icons
setIcons(icon, document.querySelector('.icon'))

//Set degree to celsius/ Fahrenheit
temperatureSection.addEventListener('click', ()=>{
if(temperaturSpan.textContent === 'F°'){
temperaturSpan.textContent = 'C°'
temperatureDegree.textContent = Math.floor(celsius)
} else {
temperaturSpan.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])
}
})
Loading