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

Skip to content

Commit 986c13b

Browse files
committed
Akif-HomeworkWeek3
1 parent 82296eb commit 986c13b

File tree

1 file changed

+158
-0
lines changed

1 file changed

+158
-0
lines changed

Week3/akif-week3.js

Lines changed: 158 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,158 @@
1+
// STRINGS! --------------
2+
let myString = 'hello,this,is,a,difficult,to,read,sentence';
3+
console.log(myString);
4+
console.log(myString.length);
5+
myString = myString.replace(/[,]/g, ' ');
6+
console.log(myString);
7+
8+
// ARRAYS! -------------------------------------------------
9+
let favoriteAnimals = ['blowfish', 'capricorn', 'giraffe'];
10+
favoriteAnimals.push('turtle');
11+
console.log(favoriteAnimals);
12+
favoriteAnimals.splice(1, 0, 'meerkat');
13+
console.log("i added a new value 'meerkat' to the array");
14+
console.log(favoriteAnimals);
15+
console.log('The array has a length of: ' + favoriteAnimals.length);
16+
favoriteAnimals.splice(3, 1);
17+
console.log(favoriteAnimals);
18+
console.log('The item you are looking for is at index: ' + favoriteAnimals.indexOf('meerkat'));
19+
favoriteAnimals.splice(favoriteAnimals.indexOf('meerkat'), 1);
20+
21+
// MORE JAVASCRIPT ! ------------------------------------------------
22+
// -----1111111111111111111-----------
23+
function getSum(a, b, c) {
24+
return a + b + c;
25+
}
26+
27+
// -----222222222222222222-------------
28+
function colorCar(color) {
29+
return 'a ' + color + ' car';
30+
}
31+
32+
//-----3333333333333333333--------------
33+
const myBooks = {
34+
Dostoyevsky: 'Crime and Punishment',
35+
'Franz Kafka': 'The Trial',
36+
'Anne Frank': 'Diarys',
37+
};
38+
39+
function getBook(library) {
40+
for (let book in library) {
41+
console.log(book + ' - ' + library[book]);
42+
}
43+
}
44+
getBook(myBooks);
45+
46+
// -----444444444444444444------------------
47+
const vehicleCodes = {
48+
1: 'car',
49+
2: 'motorbike',
50+
};
51+
52+
function vehicleType(color, code) {
53+
console.log('A ' + color + ' ' + vehicleCodes[code]);
54+
}
55+
56+
vehicleType('blue', 2);
57+
58+
// _-------555555555555555555--------------------
59+
console.log(3 === 3 ? 'yes' : 'no');
60+
61+
// -------66666666666666666666---------------------
62+
function vehicle(color, code, age) {
63+
if (age > 0) {
64+
age = 'used';
65+
} else {
66+
age = 'new';
67+
}
68+
console.log('A ' + color + ' ' + age + ' ' + vehicleCodes[code]);
69+
}
70+
71+
vehicle('blue', 1, 5);
72+
73+
// -------777777777777 && 888888888888888--------------------
74+
let vehicleList = ['car', 'motorbike', 'caravan', 'bike', 'truck'];
75+
76+
console.log('Third element of the array is ' + vehicleList[2]);
77+
78+
// --------9999999999999999999999 -----------------------------
79+
function vehicle1(color, code, age) {
80+
if (age > 1) {
81+
age = 'used';
82+
} else {
83+
age = 'new';
84+
}
85+
console.log('A ' + color + ' ' + age + ' ' + vehicleList[code]);
86+
}
87+
88+
vehicle1('green', 3, 1);
89+
90+
//-------10 10 10 10 10 10 10 10 ---------------------
91+
92+
// function advertisement(arrname) {
93+
// for (let i = 0; i < arrname.length; i++) {
94+
// arrname[i] += 's';
95+
// }
96+
97+
// for (let i = 0; i < arrname.length - 2; i++) {
98+
// arrname[i] += ',';
99+
// }
100+
101+
// arrname[arrname.length - 2] += ' and';
102+
103+
// console.log("Amazing Joe's Garage, we service " + arrname.join(' ') + '.');
104+
// }
105+
106+
function advertisement(arrname) {
107+
let vehicles1 = arrname.slice(0, arrname.length - 1).join('s, ');
108+
let lastVehicle = arrname[arrname.length - 1];
109+
110+
console.log(`"Amazing Joe's Garage, we service ${vehicles1}s and ${lastVehicle}s."`);
111+
}
112+
113+
advertisement(vehicleList);
114+
115+
// --------11 11 11 111 11 11 11 11 ----------------------
116+
vehicleList.push('ship');
117+
advertisement(vehicleList);
118+
119+
// ---12 12 12 12 12 12 12 12 // 13 13 13 // 14 14 14 14 -------------------------
120+
const teachers = {};
121+
teachers.HTML = 'Philipp Beau';
122+
teachers.CSS = 'Rob van Kruijsdijk';
123+
teachers.GIT = 'Unmesh Joshi';
124+
teachers.JS = 'Yash Kapila';
125+
console.log(teachers);
126+
127+
// ---15 15 15 15 15 15 15 15 15 --------------------------------
128+
let x = [1, 2, 3];
129+
let y = [1, 2, 3];
130+
let z = y;
131+
132+
console.log(x == y); // false
133+
console.log(x === y); // false
134+
console.log(x == z); // false
135+
console.log(x === z); // false
136+
console.log(y == z); // true
137+
console.log(y === z); // true
138+
139+
// When i use == or ===, it compares whether they are same array or not.
140+
// to look they have a same content:
141+
console.log(x.toString() === y.toString()); // true
142+
143+
// ---- 16 16 16 16 16 16 16 ------------------
144+
let o1 = { foo: 'bar' };
145+
let o2 = { foo: 'bar' };
146+
let o3 = o2;
147+
148+
o2.foo = 'o2-changed';
149+
console.log(o3); //changing o2 change o3
150+
o1.foo = 'o1-changed';
151+
console.log(o3); //changing o1 doesnt change o3
152+
// **Does the order that you assign (o3 = o2 or o2 = o3) matter?
153+
// Yes absolutely matter. if we write o2 = o3, o2 would be declared twice and cause ERROR.
154+
155+
// ----17 17 17 17 17 17 17 17 ----------------
156+
let bar = 42;
157+
console.log(typeof typeof bar); // string
158+
// Because typeof 'bar' is number and typeof 'number' is string. Number is text.

0 commit comments

Comments
 (0)