From a93f35de8d3bec23c13145f9c1a45a538ae25454 Mon Sep 17 00:00:00 2001 From: Akif Date: Mon, 4 Mar 2019 16:07:34 +0100 Subject: [PATCH 1/5] JSHomework2 Akif --- .../JSHomeworkWeek2-Akif/index.html | 12 ++ .../JSHomeworkWeek2-Akif/main.js | 108 ++++++++++++++++++ 2 files changed, 120 insertions(+) create mode 100644 Week2/code_examples/JSHomeworkWeek2-Akif/index.html create mode 100644 Week2/code_examples/JSHomeworkWeek2-Akif/main.js diff --git a/Week2/code_examples/JSHomeworkWeek2-Akif/index.html b/Week2/code_examples/JSHomeworkWeek2-Akif/index.html new file mode 100644 index 000000000..e0edbf103 --- /dev/null +++ b/Week2/code_examples/JSHomeworkWeek2-Akif/index.html @@ -0,0 +1,12 @@ + + + + + + JS + + + + + + diff --git a/Week2/code_examples/JSHomeworkWeek2-Akif/main.js b/Week2/code_examples/JSHomeworkWeek2-Akif/main.js new file mode 100644 index 000000000..c2257e0e6 --- /dev/null +++ b/Week2/code_examples/JSHomeworkWeek2-Akif/main.js @@ -0,0 +1,108 @@ +// Part 1 Hello World +console.log('Hello World'); // English +console.log('Merhaba Dunya'); // Turkish +console.log('Hallo Wereld'); // Dutch +console.log('مرحبا بالعالم'); // Arabic + +// Part 2 Error ----------------------------------------- +console.log("I'm awesome"); + +// Part 3 Console.log(x) -------------------------------- +let x; +console.log('the value of my variable x will be: numberOfTheStudents'); +console.log(x); +x = 16; +console.log('the value of my variable x will be: numberOfTheStudents'); +console.log(x); + +// Part 4 String y --------------------------------------- +let y = 'I love you JavaScript'; +console.log('the value of my variable y will be: feelingAboutJavaScript'); +console.log(y); +y = 'I will learn you'; +console.log('the value of my variable y will be: myPlanAboutJavaScript'); +console.log(y); + +// Part 5 Round a number --------------------------------- +let z = 7.25; +console.log(z); +let a = Math.round(z); +console.log(a); +let b = Math.max(z, a); +console.log(b); + +// Part 6 Arrays ------------------------------------------ +let myNumbers = []; +console.log('the value of my variable y will be: myLuckyNumbers'); +console.log(myNumbers); +let myFavouriteAnimals = ['cat', 'butterfly', 'bear']; +console.log(myFavouriteAnimals); +myFavouriteAnimals.push('baby pig'); +console.log(myFavouriteAnimals); + +// Part 7 More Strings - Length ----------------------------- +let myString = + 'JavaScript (JS) is a lightweight interpreted or JIT-compiled programming language with first-class functions.'; +console.log(myString); +console.log(myString.length); + +// Part 8 typeof ------------------------------------------- +let k = 42; +let l = 'Hello World'; +let m; +let n = true; +console.log(k, l, m, n); +console.log('the types of my variable accordingly are: number, string, undefined, boolean'); +console.log(typeof k, typeof l, typeof m, typeof n); +if (typeof k != typeof l) { + console.log('Not Same Type'); +} +if (typeof k != typeof m) { + console.log('Not Same Type'); +} +if (typeof k != typeof n) { + console.log('Not Same Type'); +} +if (typeof l != typeof m) { + console.log('Not Same Type'); +} +if (typeof l != typeof n) { + console.log('Not Same Type'); +} +if (typeof m != typeof n) { + console.log('Not Same Type'); +} + +// Part 9 Remainder % ----------------------------------------- +x = 7; +x %= 3; +console.log(x); + +y = 100; +console.log((y %= 15)); + +if (y % 2 === 0) { + console.log(y + ' is a even number'); +} +y = 13; +if (y % 2 === 1) { + console.log(y + ' is a odd number'); +} + +// Part 10 -------------------------------------------------------------- +let arr = [13, 'I am a programmer', undefined, null]; +console.log(arr); + +function arrayTypeChecker(b) { + for (let i = 0; i < b.length; i++) { + if (typeof b[i] !== typeof b[i + 1]) { + return 'Array includes DIFFERENT data types'; + } else { + return 'Array includes SAME data types'; + } + } +} + +console.log(arrayTypeChecker(arr)); + +console.log(6 / 0 === 10 / 0); From 4ebdf172cb778edecfd19f616f55857fe316ca0e Mon Sep 17 00:00:00 2001 From: Akif Date: Tue, 5 Mar 2019 10:09:30 +0100 Subject: [PATCH 2/5] JS Week_2 Homework --- .../JSHomeworkWeek2-Akif/main.js => akif.js} | 0 Week2/code_examples/JSHomeworkWeek2-Akif/index.html | 12 ------------ 2 files changed, 12 deletions(-) rename Week2/{code_examples/JSHomeworkWeek2-Akif/main.js => akif.js} (100%) delete mode 100644 Week2/code_examples/JSHomeworkWeek2-Akif/index.html diff --git a/Week2/code_examples/JSHomeworkWeek2-Akif/main.js b/Week2/akif.js similarity index 100% rename from Week2/code_examples/JSHomeworkWeek2-Akif/main.js rename to Week2/akif.js diff --git a/Week2/code_examples/JSHomeworkWeek2-Akif/index.html b/Week2/code_examples/JSHomeworkWeek2-Akif/index.html deleted file mode 100644 index e0edbf103..000000000 --- a/Week2/code_examples/JSHomeworkWeek2-Akif/index.html +++ /dev/null @@ -1,12 +0,0 @@ - - - - - - JS - - - - - - From 82296eba00cfb6a8fb2ed47093b0e9e5a45abdf2 Mon Sep 17 00:00:00 2001 From: Akif Date: Sat, 9 Mar 2019 20:16:23 +0100 Subject: [PATCH 3/5] makes some corrections --- Week2/akif.js | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/Week2/akif.js b/Week2/akif.js index c2257e0e6..386513224 100644 --- a/Week2/akif.js +++ b/Week2/akif.js @@ -9,26 +9,26 @@ console.log("I'm awesome"); // Part 3 Console.log(x) -------------------------------- let x; -console.log('the value of my variable x will be: numberOfTheStudents'); +console.log('the value of my variable x will be: 16'); console.log(x); x = 16; -console.log('the value of my variable x will be: numberOfTheStudents'); +console.log('the value of my variable x will be: 16'); console.log(x); // Part 4 String y --------------------------------------- let y = 'I love you JavaScript'; -console.log('the value of my variable y will be: feelingAboutJavaScript'); +console.log('the value of my variable y will be: I love you JavaScript'); console.log(y); y = 'I will learn you'; -console.log('the value of my variable y will be: myPlanAboutJavaScript'); +console.log('the value of my variable y will be: I will learn you'); console.log(y); // Part 5 Round a number --------------------------------- -let z = 7.25; +const z = 7.25; console.log(z); -let a = Math.round(z); +const a = Math.round(z); console.log(a); -let b = Math.max(z, a); +const b = Math.max(z, a); console.log(b); // Part 6 Arrays ------------------------------------------ @@ -54,22 +54,22 @@ let n = true; console.log(k, l, m, n); console.log('the types of my variable accordingly are: number, string, undefined, boolean'); console.log(typeof k, typeof l, typeof m, typeof n); -if (typeof k != typeof l) { +if (typeof k !== typeof l) { console.log('Not Same Type'); } -if (typeof k != typeof m) { +if (typeof k !== typeof m) { console.log('Not Same Type'); } -if (typeof k != typeof n) { +if (typeof k !== typeof n) { console.log('Not Same Type'); } -if (typeof l != typeof m) { +if (typeof l !== typeof m) { console.log('Not Same Type'); } -if (typeof l != typeof n) { +if (typeof l !== typeof n) { console.log('Not Same Type'); } -if (typeof m != typeof n) { +if (typeof m !== typeof n) { console.log('Not Same Type'); } @@ -94,7 +94,7 @@ let arr = [13, 'I am a programmer', undefined, null]; console.log(arr); function arrayTypeChecker(b) { - for (let i = 0; i < b.length; i++) { + for (let i = 0; i < b.length - 1; i++) { if (typeof b[i] !== typeof b[i + 1]) { return 'Array includes DIFFERENT data types'; } else { From 986c13bbf2ff266a6c7d1385b9bda9c1a2ee67db Mon Sep 17 00:00:00 2001 From: Akif Date: Wed, 13 Mar 2019 21:13:14 +0100 Subject: [PATCH 4/5] Akif-HomeworkWeek3 --- Week3/akif-week3.js | 158 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 158 insertions(+) create mode 100644 Week3/akif-week3.js diff --git a/Week3/akif-week3.js b/Week3/akif-week3.js new file mode 100644 index 000000000..4d720c2d4 --- /dev/null +++ b/Week3/akif-week3.js @@ -0,0 +1,158 @@ +// STRINGS! -------------- +let myString = 'hello,this,is,a,difficult,to,read,sentence'; +console.log(myString); +console.log(myString.length); +myString = myString.replace(/[,]/g, ' '); +console.log(myString); + +// ARRAYS! ------------------------------------------------- +let favoriteAnimals = ['blowfish', 'capricorn', 'giraffe']; +favoriteAnimals.push('turtle'); +console.log(favoriteAnimals); +favoriteAnimals.splice(1, 0, 'meerkat'); +console.log("i added a new value 'meerkat' to the array"); +console.log(favoriteAnimals); +console.log('The array has a length of: ' + favoriteAnimals.length); +favoriteAnimals.splice(3, 1); +console.log(favoriteAnimals); +console.log('The item you are looking for is at index: ' + favoriteAnimals.indexOf('meerkat')); +favoriteAnimals.splice(favoriteAnimals.indexOf('meerkat'), 1); + +// MORE JAVASCRIPT ! ------------------------------------------------ +// -----1111111111111111111----------- +function getSum(a, b, c) { + return a + b + c; +} + +// -----222222222222222222------------- +function colorCar(color) { + return 'a ' + color + ' car'; +} + +//-----3333333333333333333-------------- +const myBooks = { + Dostoyevsky: 'Crime and Punishment', + 'Franz Kafka': 'The Trial', + 'Anne Frank': 'Diarys', +}; + +function getBook(library) { + for (let book in library) { + console.log(book + ' - ' + library[book]); + } +} +getBook(myBooks); + +// -----444444444444444444------------------ +const vehicleCodes = { + 1: 'car', + 2: 'motorbike', +}; + +function vehicleType(color, code) { + console.log('A ' + color + ' ' + vehicleCodes[code]); +} + +vehicleType('blue', 2); + +// _-------555555555555555555-------------------- +console.log(3 === 3 ? 'yes' : 'no'); + +// -------66666666666666666666--------------------- +function vehicle(color, code, age) { + if (age > 0) { + age = 'used'; + } else { + age = 'new'; + } + console.log('A ' + color + ' ' + age + ' ' + vehicleCodes[code]); +} + +vehicle('blue', 1, 5); + +// -------777777777777 && 888888888888888-------------------- +let vehicleList = ['car', 'motorbike', 'caravan', 'bike', 'truck']; + +console.log('Third element of the array is ' + vehicleList[2]); + +// --------9999999999999999999999 ----------------------------- +function vehicle1(color, code, age) { + if (age > 1) { + age = 'used'; + } else { + age = 'new'; + } + console.log('A ' + color + ' ' + age + ' ' + vehicleList[code]); +} + +vehicle1('green', 3, 1); + +//-------10 10 10 10 10 10 10 10 --------------------- + +// function advertisement(arrname) { +// for (let i = 0; i < arrname.length; i++) { +// arrname[i] += 's'; +// } + +// for (let i = 0; i < arrname.length - 2; i++) { +// arrname[i] += ','; +// } + +// arrname[arrname.length - 2] += ' and'; + +// console.log("Amazing Joe's Garage, we service " + arrname.join(' ') + '.'); +// } + +function advertisement(arrname) { + let vehicles1 = arrname.slice(0, arrname.length - 1).join('s, '); + let lastVehicle = arrname[arrname.length - 1]; + + console.log(`"Amazing Joe's Garage, we service ${vehicles1}s and ${lastVehicle}s."`); +} + +advertisement(vehicleList); + +// --------11 11 11 111 11 11 11 11 ---------------------- +vehicleList.push('ship'); +advertisement(vehicleList); + +// ---12 12 12 12 12 12 12 12 // 13 13 13 // 14 14 14 14 ------------------------- +const teachers = {}; +teachers.HTML = 'Philipp Beau'; +teachers.CSS = 'Rob van Kruijsdijk'; +teachers.GIT = 'Unmesh Joshi'; +teachers.JS = 'Yash Kapila'; +console.log(teachers); + +// ---15 15 15 15 15 15 15 15 15 -------------------------------- +let x = [1, 2, 3]; +let y = [1, 2, 3]; +let z = y; + +console.log(x == y); // false +console.log(x === y); // false +console.log(x == z); // false +console.log(x === z); // false +console.log(y == z); // true +console.log(y === z); // true + +// When i use == or ===, it compares whether they are same array or not. +// to look they have a same content: +console.log(x.toString() === y.toString()); // true + +// ---- 16 16 16 16 16 16 16 ------------------ +let o1 = { foo: 'bar' }; +let o2 = { foo: 'bar' }; +let o3 = o2; + +o2.foo = 'o2-changed'; +console.log(o3); //changing o2 change o3 +o1.foo = 'o1-changed'; +console.log(o3); //changing o1 doesnt change o3 +// **Does the order that you assign (o3 = o2 or o2 = o3) matter? +// Yes absolutely matter. if we write o2 = o3, o2 would be declared twice and cause ERROR. + +// ----17 17 17 17 17 17 17 17 ---------------- +let bar = 42; +console.log(typeof typeof bar); // string +// Because typeof 'bar' is number and typeof 'number' is string. Number is text. From c120d70c569c988cf2dbed295374f779261f7cfe Mon Sep 17 00:00:00 2001 From: Akif Date: Fri, 15 Mar 2019 13:51:24 +0100 Subject: [PATCH 5/5] corrections --- Week2/akif.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Week2/akif.js b/Week2/akif.js index 386513224..98dc9310d 100644 --- a/Week2/akif.js +++ b/Week2/akif.js @@ -9,7 +9,7 @@ console.log("I'm awesome"); // Part 3 Console.log(x) -------------------------------- let x; -console.log('the value of my variable x will be: 16'); +console.log('the value of my variable x will be: Undefined'); console.log(x); x = 16; console.log('the value of my variable x will be: 16');