This repository has been archived by the owner on Oct 26, 2020. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 458
Nawal week 9 #1024
Open
NawalC
wants to merge
2
commits into
CodeYourFuture:manchester3
Choose a base branch
from
NawalC:nawal-week-9
base: manchester3
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Nawal week 9 #1024
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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: | ||
|
@@ -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. | ||
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. | ||
|
@@ -47,7 +49,7 @@ function f1(val) { | |
} | ||
|
||
f1(x); | ||
console.log(x); | ||
console.log(x); // 9 | ||
|
||
const y = { x: 9 }; | ||
|
||
|
@@ -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 | ||
// ``` | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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]) | ||
} | ||
}) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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