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

JS/Core-3/Week-3/Mursel_Aysan #44

Open
wants to merge 6 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
Empty file.
Empty file.
8 changes: 7 additions & 1 deletion 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.

// Because of scope, first x in the global scope , after that second x inside local scop.

## Question 2

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

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

// it will log 10 for x .But it will give an error that y is not defined .. because the log for y made out of side the scope the y have been defined in .. (let inside the block scoped)

## Question 3

Take a look at the following code:
Expand All @@ -60,4 +64,6 @@ f2(y);
console.log(y);
```

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

//It will log 9 and x =10 and because x defined with const and const can not be reassigned (constant) the same applied for the const object if we reassigned the object or we attempted to overwrite it, but the keys for that object are not protected so we can reassign them or overwrite them.
37 changes: 37 additions & 0 deletions week-3/Homework/mandatory/1-practice/app.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
*{
margin: 0;
padding: 0;
box-sizing: border-box;
}
body{
height: 100vh;
display: flex;
justify-content: center;
flex-direction: column;
align-items: center;
background: linear-gradient(rgb(47,150,163),rgb(48,62,143));
font-family: sans-serif;
color: white;
}
.location,.temperature{
height: 30vh;
width: 50%;
display: flex;
justify-content: space-around;
align-items: center;
}
.temperature{
flex-direction: column;
}
.degree-section{
display: flex;
align-items: center;
cursor: pointer;
}
.degree-section span{
margin: 10px;
font-size: 30px;
}
.degree-section h2{
font-size: 40px;
}
24 changes: 24 additions & 0 deletions week-3/Homework/mandatory/1-practice/app.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="app.css" />
<title>Weather</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">34</h2>
<span>F</span>
</div>
<div class="temperature-description">Its frozen cold</div>
</div>
<script src='skycons.js'></script>
<script src='app.js'></script>
</body>
</html>
85 changes: 85 additions & 0 deletions week-3/Homework/mandatory/1-practice/app.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
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');
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 =>{
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;
//set Icon
setIcons(icon,document.querySelector('.icon'));
});

});

}

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

});
//Formula For CELSIUS
let celsius = (temperature - 32) * (5 / 9);
//set Icon
setIcons(icon,document.querySelector('.icon'));


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



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 =>{
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;
//set Icon
setIcons(icon,document.querySelector('.icon'));
});


function setIcons(icon,iconID){
const skycons = new Skycons({color:'white'});
const currentIcon = icon.replace(/-/g, "_").toUpperCase();
skycons.play();
return skycons.set(iconID,Skycons[currentIcon]);
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,10 @@ const personOne = {
favouriteFood: 'Spinach'
}

function introduceYourself(___________________________) {
console.log (`Hello, my name is ${name}. I am ${age} years old and my favourite food is ${favouriteFood}.`);
let{name,age,favouriteFood} = personOne;

function introduceYourself(x) {
console.log (`Hello, my name is ${x.name}. I am ${x.age} years old and my favourite food is ${x.favouriteFood}.`);
}

introduceYourself(personOne);
10 changes: 10 additions & 0 deletions week-3/Homework/mandatory/2-exercises/exercise-2/exercise-2.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,13 @@ let hogwarts = [
{ firstName: "Minerva", lastName: "McGonagall", house: "Gryffindor", pet: null, occupation: "Teacher" },
{ firstName: "Albus", lastName: "Dumbledore", house: "Gryffindor", pet: "Phoenix", occupation: "Teacher" }
]

//Alternative way
// let griF = hogwarts.filter(x => x.house ==="Gryffindor").map(x => x.firstName+x.lastName).toString();
// console.log(griF);
function GryffindorPeople([Harry,Hermione, , , , , ,Minerva,Albus]){
console.log(Harry.firstName,Harry.lastName,Hermione.firstName,Hermione.lastName,Minerva.firstName,Minerva.lastName,Albus.firstName,Albus.lastName);
}

GryffindorPeople(hogwarts);
//let[firstName,lastName,...rest] = hogwarts;
28 changes: 26 additions & 2 deletions week-3/Homework/mandatory/2-exercises/exercise-3/exercise-3.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,32 @@
{ itemName: "Hot cakes", quantity: 1, unitPrice: 2.29},
{ itemName: "Apple Pie", quantity: 2, unitPrice: 1.39},
{ itemName: "Egg McMuffin", quantity: 1, unitPrice: 2.80},
{ itemName: "Sausage McMuffin", quantity: 1, unitPrice: 3.00},
{ itemName: "Ssge McMuffin", quantity: 1, unitPrice: 3.00},
{ itemName: "Hot Coffee", quantity: 2, unitPrice: 1.00},
{ itemName: "Hash Brown", quantity: 4, unitPrice: 0.40}
]



//let[...rest]= order;
//console.log(rest[0]);



function findTotal([...rest]){
let plus = 0;

for(let i=0;i<rest.length;i++){
plus += rest[i].unitPrice*rest[i].quantity;
}

console.log('QTY \t\t\t ITEM \t\t\t\t TOTAL');

for(i=0;i<rest.length;i++){
console.log(rest[i].quantity+'\t\t\t'+rest[i].itemName+'\t\t\t'+(rest[i].unitPrice*rest[i].quantity).toFixed(2));

}

console.log('\nTotal: '+ plus);
}

findTotal(order);