From 475f279982c9f0ce7daced7b4830b2839ccfa57f Mon Sep 17 00:00:00 2001 From: Ali Ulgr Date: Thu, 28 Nov 2019 01:44:45 +0300 Subject: [PATCH 1/5] js exercise by ali --- Week1/homework/js-exercises/compareArrays.js | 11 +++++ Week1/homework/js-exercises/errorDebug.js | 2 + .../homework/js-exercises/logArrayAnimals.js | 8 ++++ Week1/homework/js-exercises/logHello.js | 11 +++++ Week1/homework/js-exercises/logLengtString.js | 4 ++ Week1/homework/js-exercises/logNumber.js | 7 ++++ Week1/homework/js-exercises/logRemainder.js | 18 ++++++++ Week1/homework/js-exercises/logString.js | 7 ++++ Week1/homework/js-exercises/roundNumber.js | 7 ++++ Week1/homework/js-exercises/typeChecker.js | 41 +++++++++++++++++++ Week1/playground.js | 25 +++++++++++ 11 files changed, 141 insertions(+) create mode 100644 Week1/homework/js-exercises/compareArrays.js create mode 100644 Week1/homework/js-exercises/errorDebug.js create mode 100644 Week1/homework/js-exercises/logArrayAnimals.js create mode 100644 Week1/homework/js-exercises/logHello.js create mode 100644 Week1/homework/js-exercises/logLengtString.js create mode 100644 Week1/homework/js-exercises/logNumber.js create mode 100644 Week1/homework/js-exercises/logRemainder.js create mode 100644 Week1/homework/js-exercises/logString.js create mode 100644 Week1/homework/js-exercises/roundNumber.js create mode 100644 Week1/homework/js-exercises/typeChecker.js create mode 100644 Week1/playground.js diff --git a/Week1/homework/js-exercises/compareArrays.js b/Week1/homework/js-exercises/compareArrays.js new file mode 100644 index 000000000..5329fa1fe --- /dev/null +++ b/Week1/homework/js-exercises/compareArrays.js @@ -0,0 +1,11 @@ +'use strict' +const bestDefender = ["Van Dijk", "Ramos", "Söyüncü"]; +const bestForward = ["Messi","Ronaldo","Salah","Neymar","Lewandowski","Suarez","Mbappe"]; +console.log('The length of the array is... ' + bestDefender.length); +console.log('The length of the array is... ' + bestForward.length); + +if (bestDefender.length === bestForward.length){ + console.log("They are the same!") +} else { + console.log("Two different sizes!"); +} \ No newline at end of file diff --git a/Week1/homework/js-exercises/errorDebug.js b/Week1/homework/js-exercises/errorDebug.js new file mode 100644 index 000000000..38fdda610 --- /dev/null +++ b/Week1/homework/js-exercises/errorDebug.js @@ -0,0 +1,2 @@ +'use strict' +console.log("I'm awesome"); diff --git a/Week1/homework/js-exercises/logArrayAnimals.js b/Week1/homework/js-exercises/logArrayAnimals.js new file mode 100644 index 000000000..67517a41c --- /dev/null +++ b/Week1/homework/js-exercises/logArrayAnimals.js @@ -0,0 +1,8 @@ +'use strict' +let camels =[]; +console.log("These are the kinds of camels in Turkey"); +console.log(camels); +let favAnimals =["lion","eagle","horse"]; +console.log(favAnimals); +favAnimals.push("Piglet"); +console.log(favAnimals); diff --git a/Week1/homework/js-exercises/logHello.js b/Week1/homework/js-exercises/logHello.js new file mode 100644 index 000000000..d6d8ec873 --- /dev/null +++ b/Week1/homework/js-exercises/logHello.js @@ -0,0 +1,11 @@ +'use strict' +console.log("Hello world!"); +console.log("Halo, dunia!"); +console.log("Merhaba, dünya!"); +console.log("Ciao, mondo!"); +console.log("Hola, mundo!"); +console.log("Hallo Wereld!"); +console.log("Silav, Cîhanê!"); +console.log("Pozdrav, svijete!"); +console.log("Bonjour tout le monde!"); +console.log("Salam, dünya!"); \ No newline at end of file diff --git a/Week1/homework/js-exercises/logLengtString.js b/Week1/homework/js-exercises/logLengtString.js new file mode 100644 index 000000000..db3ebdcf5 --- /dev/null +++ b/Week1/homework/js-exercises/logLengtString.js @@ -0,0 +1,4 @@ +'use strict' +let mySentence = "Programming is so interesting!"; +let x = mySentence.length; +console.log(x); \ No newline at end of file diff --git a/Week1/homework/js-exercises/logNumber.js b/Week1/homework/js-exercises/logNumber.js new file mode 100644 index 000000000..4a910236b --- /dev/null +++ b/Week1/homework/js-exercises/logNumber.js @@ -0,0 +1,7 @@ +'use strict' +let numberX; +console.log("I did not assign any value to numberX"); +console.log(numberX); +numberX = 13; +console.log("numberX might be"); +console.log(numberX); \ No newline at end of file diff --git a/Week1/homework/js-exercises/logRemainder.js b/Week1/homework/js-exercises/logRemainder.js new file mode 100644 index 000000000..116aedd52 --- /dev/null +++ b/Week1/homework/js-exercises/logRemainder.js @@ -0,0 +1,18 @@ +'use strict' +//1. If x equals 7, and the only other statement is x = x % 3, what would be the value of x after the calculation? +let x = 7; +x = x % 3; +console.log(x); +// The answer is 1 because, "%" this operator is division remainder and after division of 7 to the 2, the remainder is 1. + +//2. If y equals 21, and the only other statement is y = y % 4, what would be the value of y after the calculation? +let y = 21; +y = y % 4; +console.log(y); +// The answer is 1 because, "%" this operator is division remainder and after division of 21 to the 4, the remainder is 1. + +//3. If z equals 13, and the only other statement is z = z % 2, what would be the value of z after the calculation? +let z = 13; +z = z % 2; +console.log(z); +// The answer is 1 because, "%" this operator is division remainder and after division of 13 to the 2, the remainder is 1. \ No newline at end of file diff --git a/Week1/homework/js-exercises/logString.js b/Week1/homework/js-exercises/logString.js new file mode 100644 index 000000000..aecbecf90 --- /dev/null +++ b/Week1/homework/js-exercises/logString.js @@ -0,0 +1,7 @@ +'use strict' +let myString = "Ali Ulger"; +console.log("I am"); +console.log(myString); +myString = "Ali Can"; +console.log("Sorry, I wrote it wrong, My real name is,"); +console.log(myString); diff --git a/Week1/homework/js-exercises/roundNumber.js b/Week1/homework/js-exercises/roundNumber.js new file mode 100644 index 000000000..e37cc1343 --- /dev/null +++ b/Week1/homework/js-exercises/roundNumber.js @@ -0,0 +1,7 @@ +'use strict' +let z = 7.25; +console.log(z); +let a = Math.round(z); +console.log(a); +let highestValue = Math.max(a, z); +console.log(highestValue); diff --git a/Week1/homework/js-exercises/typeChecker.js b/Week1/homework/js-exercises/typeChecker.js new file mode 100644 index 000000000..bdb7d1af9 --- /dev/null +++ b/Week1/homework/js-exercises/typeChecker.js @@ -0,0 +1,41 @@ +'use strict' +const cars = ["Toyota", "Volvo", "BMW"]; +const bicycles = ["Bianchi", "Gazelle", "Salcano"]; +const myCar = "Mazda"; +const myBicycle = "Gazelle"; + +if (typeof cars == typeof bicycles) { + console.log('SAME TYPE'); +} else { + console.log('Not the same...'); +} + +if (typeof cars == typeof myCar) { + console.log('SAME TYPE'); +} else { + console.log('Not the same...'); +} + +if (typeof cars == typeof myBicycle) { + console.log('SAME TYPE'); +} else { + console.log('Not the same...'); +} + +if (typeof bicycles == typeof myCar) { + console.log('SAME TYPE'); +} else { + console.log('Not the same...'); +} + +if (typeof bicycles == typeof myBicycle) { + console.log('SAME TYPE'); +} else { + console.log('Not the same...'); +} + +if (typeof myCar == typeof myBicycle) { + console.log('SAME TYPE'); +} else { + console.log('Not the same...'); +} \ No newline at end of file diff --git a/Week1/playground.js b/Week1/playground.js new file mode 100644 index 000000000..83ffd2349 --- /dev/null +++ b/Week1/playground.js @@ -0,0 +1,25 @@ +'use strict'; +let x =5; +let typeOfX = typeof x; +console.log(typeOfX); +let y ="text"; +let typeOfY = typeof y; +console.log(typeOfY); +let z =true; +let typeOfZ = typeof z; +console.log(typeOfZ); +let a; +let typeOfA = typeof a; +console.log(typeOfA); + + +const foods = ["melon", "chocolate", "kebap"]; + +const city = { + name:"konya", + population:"2000000", + capital:false, +}; + +console.log(city); + From fe3403a5b18d3dc1daa7e5ccea5612c5a008bac6 Mon Sep 17 00:00:00 2001 From: aliulgr13 <56728123+aliulgr13@users.noreply.github.com> Date: Sun, 1 Dec 2019 01:20:29 +0300 Subject: [PATCH 2/5] Update compareArrays.js --- Week1/homework/js-exercises/compareArrays.js | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/Week1/homework/js-exercises/compareArrays.js b/Week1/homework/js-exercises/compareArrays.js index 5329fa1fe..f8bfe5ae5 100644 --- a/Week1/homework/js-exercises/compareArrays.js +++ b/Week1/homework/js-exercises/compareArrays.js @@ -1,11 +1,11 @@ 'use strict' -const bestDefender = ["Van Dijk", "Ramos", "Söyüncü"]; -const bestForward = ["Messi","Ronaldo","Salah","Neymar","Lewandowski","Suarez","Mbappe"]; -console.log('The length of the array is... ' + bestDefender.length); -console.log('The length of the array is... ' + bestForward.length); +const bestDefenders = ["Van Dijk", "Ramos", "Söyüncü"]; +const bestForwards = ["Messi","Ronaldo","Salah","Neymar","Lewandowski","Suarez","Mbappe"]; +console.log('The length of the array is... ' + bestDefenders.length); +console.log('The length of the array is... ' + bestForwards.length); -if (bestDefender.length === bestForward.length){ +if (bestDefenders.length === bestForwards.length){ console.log("They are the same!") } else { console.log("Two different sizes!"); -} \ No newline at end of file +} From 773a7d828de8333cc64fa4b214009a108176fb7f Mon Sep 17 00:00:00 2001 From: aliulgr13 <56728123+aliulgr13@users.noreply.github.com> Date: Sun, 1 Dec 2019 01:22:07 +0300 Subject: [PATCH 3/5] Update logLengtString.js --- Week1/homework/js-exercises/logLengtString.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Week1/homework/js-exercises/logLengtString.js b/Week1/homework/js-exercises/logLengtString.js index db3ebdcf5..38caf5e1d 100644 --- a/Week1/homework/js-exercises/logLengtString.js +++ b/Week1/homework/js-exercises/logLengtString.js @@ -1,4 +1,4 @@ 'use strict' let mySentence = "Programming is so interesting!"; -let x = mySentence.length; -console.log(x); \ No newline at end of file +let mySentenceLength = mySentence.length; +console.log(mySentenceLength); From 7d57c0cca9391bff83c9dc40bcbec870361aea23 Mon Sep 17 00:00:00 2001 From: Ali Ulgr Date: Mon, 2 Dec 2019 20:24:00 +0300 Subject: [PATCH 4/5] ; delete --- Week1/playground.js | 3 +- Week2/playground.js | 67 +++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 69 insertions(+), 1 deletion(-) create mode 100644 Week2/playground.js diff --git a/Week1/playground.js b/Week1/playground.js index 83ffd2349..46384913f 100644 --- a/Week1/playground.js +++ b/Week1/playground.js @@ -21,5 +21,6 @@ const city = { capital:false, }; -console.log(city); +console.log(city) + diff --git a/Week2/playground.js b/Week2/playground.js new file mode 100644 index 000000000..08cb8998f --- /dev/null +++ b/Week2/playground.js @@ -0,0 +1,67 @@ +/*let s = "Hello".toLowerCase(); +let l = s.length; + +function sum(a, b) { + return a + b; +} +let max = function (a, b) { + return a > b ? a : b; +} + +let s1 = sum(4, 5); +let s2 = 4 + 5; + +if (s2 == s1) { + console.log("same"); +} else { + console.log("not same"); +} +*/ +/* Statemens: + let s2 = 4 + 5; + console.log("not same"); + let s = "Hello".toLowerCase(); +let l = s.length; +*/ + +/* Expressıons: + sum(a, b) + sum(4, 5) + "Hello".toLowerCase(); + (s2 == s1) +*/ + +/*const shoes = "blue"; +const shirt = "red"; +const pants = "green"; + +if (shoes === "green" && shirt === "green" && pants === "green" ) { + console.log("all of clothes are green"); + } + + if (shoes === "green" || shirt === "green" || pants === "green" ) { + console.log("one of clothes are green"); + } + + if (pants === "green" ) { + console.log("your pants are green"); + } + */ + + const month ="April"; + let season =""; + + switch (month) { + case "January": + season = "winter"; + break; + + case "April": + season ="spring" ; + break; + + default: + season = "summer"; + } + + console.log(season); \ No newline at end of file From 8a753744a636187138dee9b7cc141f6356fc7b6e Mon Sep 17 00:00:00 2001 From: Ali Ulgr Date: Thu, 5 Dec 2019 19:27:08 +0300 Subject: [PATCH 5/5] week2 --- .../homework/js-exercises/evenOddReporter.js | 13 ++++++ .../homework/js-exercises/gradeCalculator.js | 44 +++++++++++++++++++ Week2/homework/js-exercises/readingList.js | 19 ++++++++ Week2/homework/js-exercises/recipeCard.js | 26 +++++++++++ Week2/homework/js-exercises/removeComma.js | 11 +++++ Week2/homework/js-exercises/wantsDrink.js | 14 ++++++ 6 files changed, 127 insertions(+) create mode 100644 Week2/homework/js-exercises/evenOddReporter.js create mode 100644 Week2/homework/js-exercises/gradeCalculator.js create mode 100644 Week2/homework/js-exercises/readingList.js create mode 100644 Week2/homework/js-exercises/recipeCard.js create mode 100644 Week2/homework/js-exercises/removeComma.js create mode 100644 Week2/homework/js-exercises/wantsDrink.js diff --git a/Week2/homework/js-exercises/evenOddReporter.js b/Week2/homework/js-exercises/evenOddReporter.js new file mode 100644 index 000000000..16151f365 --- /dev/null +++ b/Week2/homework/js-exercises/evenOddReporter.js @@ -0,0 +1,13 @@ +'use strict' +// Create a for loop, that iterates from 0 to 20. +// Create a conditional statement that checks if the value of the counter variable is odd or even. +// If it's odd, log to the console The number [PUT_NUMBER_HERE] is odd!. +// If it's even, log to the console The number [PUT_NUMBER_HERE] is even!. + +for(let i=0; i<20; i++) { + if (i%2===0) { + console.log("The number "+i+ " is even!."); + } else { + console.log("The number "+i+ " is odd!."); + } +} \ No newline at end of file diff --git a/Week2/homework/js-exercises/gradeCalculator.js b/Week2/homework/js-exercises/gradeCalculator.js new file mode 100644 index 000000000..28f27d173 --- /dev/null +++ b/Week2/homework/js-exercises/gradeCalculator.js @@ -0,0 +1,44 @@ +'use strict' +// convert the score into a percentage +// calculate what grade corresponds with that percentage, and +// shows in the command line the result: the grade and the percentage +// When writing the script, make use of the following grade scores: +// Grade A (90% - 100%) +// Grade B (80% - 89%) +// Grade C (70% - 79%) +// Grade D (60% - 69%) +// Grade E (50% - 59%) +// Grade F (0% - 49%) + + +function gradeCalculator(score) { + //To be able to show the result of decimal number I used here Math.round. + score = Math.round(score); + let grade; + //I use switch by evaluating true statement. + switch(true) { + case (score <= 100 && score >= 90): + grade = 'A'; + break; + case (score <= 89 && score >= 80): + grade = 'B'; + break; + case (score <= 79 && score >= 70): + grade = 'C'; + break; + case (score <= 69 && score >= 60): + grade = 'D'; + break; + case (score <= 59 && score >= 50): + grade = 'E'; + break; + case (score <= 49 && score >= 0): + grade = 'F'; + break; + default: + console.log("You got a INVALID SCORE"); + } + return ("You got a " +grade+ " (" +score+ "%)!"); +}; +console.log(gradeCalculator(1)); + \ No newline at end of file diff --git a/Week2/homework/js-exercises/readingList.js b/Week2/homework/js-exercises/readingList.js new file mode 100644 index 000000000..086dd4715 --- /dev/null +++ b/Week2/homework/js-exercises/readingList.js @@ -0,0 +1,19 @@ +'use strict' +// Declare a variable that holds an array of 3 objects, where each object describes a book and has properties for the title (string), author (string), and alreadyRead (boolean indicating if you read it yet). +// Loop through the array of books. +// For each book, log the book title and book author like so: "The Hobbit by J.R.R. Tolkien". +// Create a conditional statement to change the log depending on whether you read it yet or not. If you read it, log a string like You already read "The Hobbit" right after the log of the book details +// If you haven't read it log a string like You still need to read "The Lord of the Rings" + +let books = [{title:"1984", author:"George Orwell", alreadyRead:false}, + {title:"Improbable", author:"Adam Fawer", alreadyRead:true}, + {title:"The Da Vinci Code", author:"Dan Brown", alreadyRead:true}]; + +for (var i = 0; i < books.length; i++) { + console.log(books[i].title +" by "+ books[i].author ); + if(books[i].alreadyRead===true){ + console.log("You already read "+ books[i].title); + }else { + console.log("You still need to read "+ books[i].title); + } +} diff --git a/Week2/homework/js-exercises/recipeCard.js b/Week2/homework/js-exercises/recipeCard.js new file mode 100644 index 000000000..6cabd6f59 --- /dev/null +++ b/Week2/homework/js-exercises/recipeCard.js @@ -0,0 +1,26 @@ +'use strict' +// Declare a variable that holds an object (your meal recipe). +// Give the object 3 properties: a title (string), a servings (number) and an ingredients (array of strings) property. +// Log each property out seperately, using a loop (for, while or do/while) + +const myBreakfastRecipe = { + mealName: "Atom", + serves: 2, + ingredients: ["100g outmeal", "One babana", "100g milk"] +}; + +//to write ingredients in the same line +// for (const property in myBreakfastRecipe) { +// console.log(`${property}: ${myBreakfastRecipe[property]}`); +// } + +for (const property in myBreakfastRecipe) { + if(typeof myBreakfastRecipe[property]==="object"){ + console.log(property+":"); + for (let ing of myBreakfastRecipe[property]){ + console.log(ing+",") + } + } else { + console.log(property+": "+myBreakfastRecipe[property] ) + } +} \ No newline at end of file diff --git a/Week2/homework/js-exercises/removeComma.js b/Week2/homework/js-exercises/removeComma.js new file mode 100644 index 000000000..f85ec40c1 --- /dev/null +++ b/Week2/homework/js-exercises/removeComma.js @@ -0,0 +1,11 @@ +'use strict' +// let myString = 'hello,this,is,a,difficult,to,read,sentence'; +// Add the variable to your file. +// Log the length of myString. +// The commas make that the sentence is quite hard to read. Find a way to remove the commas from the string and replace them with spaces. (use Google!) +// After replacing the commas, log myString to see if you succeeded. + +let myString = 'hello,this,is,a,difficult,to,read,sentence'; +console.log(myString.length); +myString = myString.replace(/,/g," "); +console.log(myString); \ No newline at end of file diff --git a/Week2/homework/js-exercises/wantsDrink.js b/Week2/homework/js-exercises/wantsDrink.js new file mode 100644 index 000000000..8faed9434 --- /dev/null +++ b/Week2/homework/js-exercises/wantsDrink.js @@ -0,0 +1,14 @@ +'use strict' +// Declare a variable that holds an empty array, called drinkTray. +// There are 3 different types of drinks: +// Create a loop that runs 5 times. On each iteration, push a drink into the drinkTray variable. The drinkTray can only hold at most two instances of the same drink type, for example it can only hold 2 colas, 2 lemonades, 2 waters. +// If there are already two instances of a drinkType then start with the next drink in the array. +// Your drinkTray should contain 2 cola, 2 lemonade and 1 water. +// Log to the console: "Hey guys, I brought a [INSERT VALUES FROM ARRAY]!" (For example: "Hey guys, I brought a cola, cola, lemonade, lemonade, water!") + +let drinkTray= []; +const drinkTypes = ['cola', 'lemonade', 'water']; +for (let i = 0; i < 5; i++) { + drinkTray.push(drinkTypes[i%3]) +} +console.log("Hey guys, I brought a "+ drinkTray.join(', ')+"!"); \ No newline at end of file