Thanks to visit codestin.com
Credit goes to github.com

Skip to content
This repository was archived by the owner on May 14, 2024. It is now read-only.

Commit 8ba1458

Browse files
committed
js2 w3 homework Enwer
1 parent 9a6b4e8 commit 8ba1458

File tree

12 files changed

+260
-0
lines changed

12 files changed

+260
-0
lines changed

Week2/.DS_Store

6 KB
Binary file not shown.

Week3/.DS_Store

6 KB
Binary file not shown.

Week3/js-exercises/.DS_Store

6 KB
Binary file not shown.

Week3/js-exercises/addSix.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
'use strict';
2+
function createBase(baseNumber) {
3+
return function(N) {
4+
return baseNumber + N;
5+
};
6+
}
7+
8+
const addSix = createBase(6);
9+
addSix(9);
10+
addSix(18);
11+
addSix(30);

Week3/js-exercises/ex3.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
// Snippet
2+
let a = 10; // global variable declared by let
3+
const x = (function() {
4+
a = 12; // global variable modified
5+
return function() {
6+
// returns outer schope` value
7+
8+
alert(a); // alerts window the output of inner function
9+
};
10+
})(); // IIFE it can directly execute the function.
11+
12+
x(); //the out put is 12, coz it declared by let .
13+
// Functions are objects in JS,and can be asinged with variable,
14+
// and this function expressions calls the function value

Week3/js-exercises/ex4.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
// Snippet
2+
const x = 9; // The const global variable
3+
function f1(val) {
4+
val = val + 1; // this function increases the value of argument val by 1 each time when it is called
5+
return val;
6+
}
7+
f1(x); // it is 10, f1 function call with argument x, but not change value of variable x
8+
9+
const y = { x: 9 }; //
10+
function f2(val) {
11+
val.x = val.x + 1;
12+
return val;
13+
}
14+
f2(y); // output is { x: 10 }, coz f2 modifies the value of object property
15+
console.log(y); //output is { x: 10 },coz f2 modifies the value of object property
16+
17+
// The const declaration creates a read-only reference to a value.
18+
// It does not mean the value it holds is immutable, just that the variable identifier cannot be reassigned.
19+
// For instance, in the case where the content is an object, this means the object's
20+
// contents (e.g., its properties) can be altered.

Week3/js-exercises/lotteryMachine.js

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
'use strict';
2+
const sayThree = n => console.log(n, 'sayThree');
3+
const sayFive = n => console.log(n, 'sayFive,');
4+
5+
function threeFive(startIndex, stopIndex, threeCallback, fiveCallback) {
6+
const numbers = [];
7+
for (i = startIndex; i <= stopIndex; i++) {
8+
numbers.push(i);
9+
console.log(numbers);
10+
}
11+
numbers.forEach(e => {
12+
if (e % 15 === 0) {
13+
sayThree(e);
14+
sayFive(e);
15+
} else if (e % 3 === 0) {
16+
sayThree(e);
17+
} else if (e % 5 === 0) {
18+
sayFive(e);
19+
}
20+
});
21+
}
22+
threeFive(10, 15, sayThree, sayFive);

Week3/js-exercises/project/.DS_Store

6 KB
Binary file not shown.

Week3/js-exercises/project/tips.css

Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
* {
2+
margin: 0;
3+
padding: 0;
4+
outline: none;
5+
}
6+
7+
body{
8+
font-family:Robotto;
9+
background: linear-gradient(to left, #AD133A, #1F050B);
10+
color: black;
11+
}
12+
13+
#container{
14+
height: 550px;
15+
width: 360px;
16+
margin: 100px auto;
17+
background:white;
18+
box-shadow: 0 0 3px #1F050B;
19+
border-radius: 20px;
20+
}
21+
22+
h1{
23+
background: #1F050B;
24+
color: white;
25+
padding: 10px 100px;
26+
font-size: 18px;
27+
border-radius: 20px 20px 0 0;
28+
}
29+
30+
form label {
31+
display: block;
32+
margin: 25px 15px;
33+
font-weight: bold;
34+
}
35+
36+
37+
form input,
38+
form select {
39+
padding-left: 20px;
40+
margin: 10px 0;
41+
}
42+
43+
form input[type='text'] {
44+
width: 90px;
45+
}
46+
47+
#bill{
48+
font-size: 15px;
49+
background-color: white;
50+
width: 60%;
51+
padding: 5px 5px 8px 8px;
52+
}
53+
54+
#totalpeople{
55+
font-size: 15px;
56+
background-color: white;
57+
width: 60%;
58+
padding: 5px 5px 8px 8px;
59+
margin-left: 20px;
60+
}
61+
62+
#service {
63+
margin-left: 20px;
64+
font-size: 25px;
65+
padding: 13px 13px 20px 20px;
66+
}
67+
68+
button {
69+
font-size: 17px;
70+
font-weight: bold;
71+
display: block;
72+
margin: 20px auto;
73+
background:#AD133A;
74+
color: white;
75+
border-radius: 5px;
76+
width: 200px;
77+
height: 50px;
78+
}
79+
80+
81+
button:hover {
82+
background: #1F050B;
83+
}
84+
85+
86+
#totaltip {
87+
font-size: 25px;
88+
margin-top: 5px;
89+
text-align: center;
90+
}
91+
92+
#totaltip small {
93+
font-size: 20px;
94+
font-weight: bold;
95+
display: block;
96+
}
97+
98+
99+
100+
101+

Week3/js-exercises/project/tips.html

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="UTF-8">
5+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
6+
<meta http-equiv="X-UA-Compatible" content="ie=edge">
7+
<link rel="stylesheet" href="tips.css">
8+
<title>Tips</title>
9+
</head>
10+
<body>
11+
<!-- container -->
12+
<div id="container">
13+
<h1>TIP CALCULATOR</h1>
14+
<div id="calculator">
15+
<form>
16+
<label for="">
17+
How much was your bill?<br>
18+
$ <input type="text" value = "" placeholder="Bill Amount" id="bill">
19+
</label>
20+
<label for="">
21+
How was your service?<br>
22+
<select id="service">
23+
<option value="" disabled selected>--Choose an Option--</option>
24+
<option value="0.3">30% - Outstanding</option>
25+
<option value="0.2">20% - Good</option>
26+
<option value="0.15">15% - It is OK</option>
27+
<option value="0.1">10% - Bad</option>
28+
<option value="0.05">5% - Terrible</option>
29+
</select>
30+
</label>
31+
<label for="">
32+
How many people are sharing this bill?<br>
33+
<input type="text" value = "" placeholder="Number of people" id="totalpeople"> People
34+
</label>
35+
<button type="button" id="calculate">Calculate!</button>
36+
</form>
37+
</div>
38+
<!-- calculator ends-->
39+
40+
<!-- totaltip -->
41+
<div id="totaltip">
42+
<span>TIP AMOUNT</span><br>
43+
<sup>$</sup><span id="tip">0.00</span><br>
44+
<small id="each">each</small>
45+
</div>
46+
47+
</div> <!-- container ends-->
48+
</body>
49+
<script src="tips.js"></script>
50+
</html>

Week3/js-exercises/project/tips.js

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
function calculateTip(){
2+
const bill = document.getElementById('bill').value;
3+
const service = document.getElementById("service").value;
4+
const numPple = document.getElementById("totalpeople").value;
5+
6+
if(bill === '' || service === 0){
7+
window.alert('Please enter the value');
8+
return;
9+
}
10+
11+
if(numPple === '' || numPple <=1){
12+
window.alert('please enter correct number')
13+
document.getElementById('each').style.display = 'none';
14+
}else{
15+
document.getElementById('each').style.display = 'block';
16+
}
17+
18+
let total = ((bill * service) / numPple).toFixed(2);
19+
20+
document.getElementById('totaltip').style.display = 'block';
21+
document.getElementById('tip').innerText = total;
22+
}
23+
24+
document.getElementById('totaltip').style.display = 'none';
25+
document.getElementById('each').style.display = 'none';
26+
27+
document.getElementById('calculate').onclick = function(){calculateTip();};
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
'use strict';
2+
// 1
3+
function removeDuplicates() {
4+
return letters.filter((a, b) => letters.indexOf(a) === b);
5+
x(letters);
6+
}
7+
const letters = ['a', 'b', 'c', 'd', 'a', 'e', 'f', 'c', 'b'];
8+
console.log(removeDuplicates(letters));
9+
// 2
10+
11+
function removeDuplicates() {
12+
return [...new Set(letters)];
13+
}
14+
const letters = ['a', 'b', 'c', 'd', 'a', 'e', 'f', 'c', 'b'];
15+
console.log(removeDuplicates(letters));

0 commit comments

Comments
 (0)