diff --git a/Week2/akif.js b/Week2/akif.js new file mode 100644 index 000000000..98dc9310d --- /dev/null +++ b/Week2/akif.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: Undefined'); +console.log(x); +x = 16; +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: I love you JavaScript'); +console.log(y); +y = 'I will learn you'; +console.log('the value of my variable y will be: I will learn you'); +console.log(y); + +// Part 5 Round a number --------------------------------- +const z = 7.25; +console.log(z); +const a = Math.round(z); +console.log(a); +const 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 - 1; 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); 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.