From 2b9fd56417727920304a767579e3e85d8caf80f8 Mon Sep 17 00:00:00 2001 From: fatih-celebi Date: Thu, 22 Sep 2022 19:45:05 +0100 Subject: [PATCH 1/9] Complete Exercise-A --- 1-exercises/A-undefined/exercise.js | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/1-exercises/A-undefined/exercise.js b/1-exercises/A-undefined/exercise.js index 0acfc78d..af9feb87 100644 --- a/1-exercises/A-undefined/exercise.js +++ b/1-exercises/A-undefined/exercise.js @@ -11,17 +11,19 @@ // Example 1 let a; -console.log(a); +console.log(a); +// a is declared as a variable. But no value has been assigned. // Example 2 function sayHello() { let message = "Hello"; } +// sayHello function created. But it has no parameter in it. let hello = sayHello(); console.log(hello); - +// hello variable has a value which is sayHello function. But this function has no parameter in it. // Example 3 function sayHelloToUser(user) { @@ -29,8 +31,11 @@ function sayHelloToUser(user) { } sayHelloToUser(); +// user declared as a parameter. But when calling a function, an argument is needed not to get undefined result. // Example 4 let arr = [1,2,3]; console.log(arr[3]); +// The index is starting from 0 in array. That`s why the last index of array "arr" is [2]. +// So there is no value for arr[3]. So, arr[3] will be undefined. From 2ed94b21c8d3ac49e0bdf377b2b429a7a3e1e349 Mon Sep 17 00:00:00 2001 From: fatih-celebi Date: Thu, 22 Sep 2022 23:50:47 +0100 Subject: [PATCH 2/9] Complete Exercise-B --- 1-exercises/B-while-loop/exercise.js | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/1-exercises/B-while-loop/exercise.js b/1-exercises/B-while-loop/exercise.js index b459888f..8427ff4a 100644 --- a/1-exercises/B-while-loop/exercise.js +++ b/1-exercises/B-while-loop/exercise.js @@ -6,9 +6,20 @@ */ function evenNumbers(n) { - // TODO + let arr = []; + let i = 0; + while (i < n*2) { + if (i % 2 === 0) { + arr.push(i); + } + i++; + } + console.log(arr); + } evenNumbers(3); // should output 0,2,4 evenNumbers(0); // should output nothing evenNumbers(10); // should output 0,2,4,6,8,10,12,14,16,18 + + From f52fef8973ddbafe1c813f9d3f5dcfce50970446 Mon Sep 17 00:00:00 2001 From: fatih-celebi Date: Fri, 23 Sep 2022 02:43:46 +0100 Subject: [PATCH 3/9] Complete Exercise-C --- 1-exercises/C-while-loop-with-array/exercise.js | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/1-exercises/C-while-loop-with-array/exercise.js b/1-exercises/C-while-loop-with-array/exercise.js index d584cd75..c119b909 100644 --- a/1-exercises/C-while-loop-with-array/exercise.js +++ b/1-exercises/C-while-loop-with-array/exercise.js @@ -1,7 +1,9 @@ /* Loops can be useful when working with arrays. - In the below example, imagine we've defined an array holding the birthdays of your closest friends. - Use a while loop to search through the array until you find the first birthday in July, then return that birthday from the function. + In the below example, imagine we've defined an array holding the + birthdays of your closest friends. + Use a while loop to search through the array until you find the first birthday in July, + then return that birthday from the function. */ const BIRTHDAYS = [ @@ -17,7 +19,11 @@ const BIRTHDAYS = [ ]; function findFirstJulyBDay(birthdays) { - // TODO + let counter = 0; + while(birthdays[counter].includes("July") != true) { + counter++; + } + return birthdays[counter]; } console.log(findFirstJulyBDay(BIRTHDAYS)); // should output "July 11th" From 48f440a4c0dbb42f767aa6d44e5845a2a3fa89fc Mon Sep 17 00:00:00 2001 From: fatih-celebi Date: Fri, 23 Sep 2022 03:04:09 +0100 Subject: [PATCH 4/9] Complete Exercise-D --- 1-exercises/D-do-while/exercise.js | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/1-exercises/D-do-while/exercise.js b/1-exercises/D-do-while/exercise.js index f10d0764..d06cc6d6 100644 --- a/1-exercises/D-do-while/exercise.js +++ b/1-exercises/D-do-while/exercise.js @@ -1,13 +1,25 @@ /* - Sometimes when using loops, we'll want to execute the body of the loop at least once. We can make sure this happens by using a do-while loop. - - If the condition in a while loop is initially false, the body of the loop will never execute - - But in a do-while loop, because the condition is checked after the body, we know that it will always execute at least once + Sometimes when using loops, we'll want to execute the body of the loop at least once. + We can make sure this happens by using a do-while loop. + - If the condition in a while loop is initially false, + the body of the loop will never execute + - But in a do-while loop, because the condition is checked after the body, + we know that it will always execute at least once - Using a do-while loop, write a function which returns the sum of the first n even numbers (starting from 0) + Using a do-while loop, write a function which returns + the sum of the first n even numbers (starting from 0) */ function evenNumbersSum(n) { - // TODO + let i = 0; + let num = 0; + let sum = 0; + do { + sum += num; + num += 2; + i++; + } while (i < n); + return sum; } console.log(evenNumbersSum(3)); // should output 6 From 579b9a030d7f054c29185e3547d181d027032322 Mon Sep 17 00:00:00 2001 From: fatih-celebi Date: Fri, 23 Sep 2022 03:20:28 +0100 Subject: [PATCH 5/9] Complete Exercise-E --- 1-exercises/E-for-loop/exercise1.js | 10 ++++++++-- 1-exercises/E-for-loop/exercise2.js | 7 ++++++- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/1-exercises/E-for-loop/exercise1.js b/1-exercises/E-for-loop/exercise1.js index db5fac64..91a53072 100644 --- a/1-exercises/E-for-loop/exercise1.js +++ b/1-exercises/E-for-loop/exercise1.js @@ -1,14 +1,20 @@ /* - for loops can be useful when we already know exactly how many times we want to loop. + for loops can be useful when we already know exactly how many times + we want to loop. Change the while loop below into a for loop. */ // Change the below code to use a for loop instead of a while loop. -let i = 0; +/*let i = 0; while(i < 26) { console.log(String.fromCharCode(97 + i)); i++; } +*/ +for (let index = 0; index < 26; index++) { + console.log(String.fromCharCode(97 + index)); + +} // The output shouldn't change. diff --git a/1-exercises/E-for-loop/exercise2.js b/1-exercises/E-for-loop/exercise2.js index 081002b2..b97ace0b 100644 --- a/1-exercises/E-for-loop/exercise2.js +++ b/1-exercises/E-for-loop/exercise2.js @@ -1,5 +1,6 @@ /* - for loops can be useful when we already know exactly how many times we want to loop. + for loops can be useful when we already know exactly how many times + we want to loop. Below we have 2 arrays which have exactly the same number of values. - The first array is a list of writers @@ -27,6 +28,10 @@ const AGES = [ ]; // TODO - Write for loop code here +for (let index = 0; index < WRITERS.length; index++) { + console.log(`${WRITERS[index]} is ${AGES[index]} years old`); +} + /* The output should look something like this: From bb086076923dda397c47e631cb968b1e85983fbf Mon Sep 17 00:00:00 2001 From: fatih-celebi Date: Fri, 23 Sep 2022 03:47:16 +0100 Subject: [PATCH 6/9] Complete Exercise-F --- 1-exercises/F-for-of-loop/exercise.js | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/1-exercises/F-for-of-loop/exercise.js b/1-exercises/F-for-of-loop/exercise.js index 65585c6a..826fa088 100644 --- a/1-exercises/F-for-of-loop/exercise.js +++ b/1-exercises/F-for-of-loop/exercise.js @@ -1,5 +1,7 @@ /* - A for-of loop is a easy and way of looping through the elements of an array, string or any other "iterable object" (think sequence of elements). + A for-of loop is a easy and way of looping through + the elements of an array, string or any other + "iterable object" (think sequence of elements). */ // TODO Use a for-of loop to output each of the tube stations below. @@ -10,7 +12,12 @@ let tubeStations = [ "Oxford Street", "Tottenham Court Road" ]; - +for (const str of tubeStations) { + console.log(str); +} // TODO Use a for-of loop to capitalise and output each letter in the string seperately. let str = "codeyourfuture"; +for (const iterator of str) { + console.log(iterator.toUpperCase()); +} From b1ca7e5321c78a8752917666b8168073e7143116 Mon Sep 17 00:00:00 2001 From: fatih-celebi Date: Fri, 23 Sep 2022 11:15:52 +0100 Subject: [PATCH 7/9] Complete Mandatory-1 --- 2-mandatory/1-weather-report.js | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/2-mandatory/1-weather-report.js b/2-mandatory/1-weather-report.js index dcc2bdb0..6f1e2e70 100644 --- a/2-mandatory/1-weather-report.js +++ b/2-mandatory/1-weather-report.js @@ -12,7 +12,11 @@ */ function getTemperatureReport(cities) { - // TODO + let cityNameAndDegree = []; + for (const temperature of cities) { + cityNameAndDegree.push(`The temperature in ${temperature} is ${temperatureService(temperature)} degrees`); + } + return cityNameAndDegree; } From 69dba08b806def93c3f124378fb7c90f59970d2b Mon Sep 17 00:00:00 2001 From: fatih-celebi Date: Fri, 23 Sep 2022 12:18:12 +0100 Subject: [PATCH 8/9] Complete Mandatory-2 --- 2-mandatory/2-retrying-random-numbers.js | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/2-mandatory/2-retrying-random-numbers.js b/2-mandatory/2-retrying-random-numbers.js index 10aab37d..dc778ddc 100644 --- a/2-mandatory/2-retrying-random-numbers.js +++ b/2-mandatory/2-retrying-random-numbers.js @@ -11,6 +11,11 @@ function generateRandomNumber() { function getRandomNumberGreaterThan50() { // TODO - implement using a do-while loop + let num; + do { + num = generateRandomNumber(); + } while (num <= 50); + return num; } /* ======= TESTS - DO NOT MODIFY ===== */ From 1b4d43917a2df00cf38cc37d96929fd24cef50a7 Mon Sep 17 00:00:00 2001 From: fatih-celebi Date: Mon, 3 Oct 2022 01:49:50 +0100 Subject: [PATCH 9/9] Complete Mandatory-3 --- 2-mandatory/3-financial-times.js | 42 +++++++++++++++++++++++++++++--- 1 file changed, 38 insertions(+), 4 deletions(-) diff --git a/2-mandatory/3-financial-times.js b/2-mandatory/3-financial-times.js index 2ce6fb73..dcfcf7c6 100644 --- a/2-mandatory/3-financial-times.js +++ b/2-mandatory/3-financial-times.js @@ -5,7 +5,13 @@ Implement the function below, which will return a new array containing only article titles which will fit. */ function potentialHeadlines(allArticleTitles) { - // TODO + let publishedTitle = []; + for (let titleCharacter of allArticleTitles ) { + if (titleCharacter.length <= 65){ + publishedTitle.push(titleCharacter); + } + } + return publishedTitle; } /* @@ -14,7 +20,19 @@ function potentialHeadlines(allArticleTitles) { (you can assume words will always be seperated by a space) */ function titleWithFewestWords(allArticleTitles) { - // TODO + let wordLength = 100; + let index = 0; + + allArticleTitles.forEach((article, i) => { + let split = article.split(" "); + + if (split.length < wordLength) { + wordLength = split.length; + index = i; + } + }); + + return allArticleTitles[index]; } /* @@ -23,7 +41,15 @@ function titleWithFewestWords(allArticleTitles) { (Hint: remember that you can also loop through the characters of a string if you need to) */ function headlinesWithNumbers(allArticleTitles) { - // TODO + let newHeadlinesWithNumbers = []; + for (let i = 0; i < allArticleTitles.length; i++) { + for (let j = 0; j < allArticleTitles[i].length; j++) { + if (allArticleTitles[i][j] === "$") { + newHeadlinesWithNumbers.push(allArticleTitles[i]) + } + } + } + return newHeadlinesWithNumbers; } /* @@ -31,7 +57,15 @@ function headlinesWithNumbers(allArticleTitles) { Implement the function below to return this number - rounded to the nearest integer. */ function averageNumberOfCharacters(allArticleTitles) { - // TODO + let newNumbers = 0; + for (let i = 0; i < allArticleTitles.length; i++) { + for (let j = 0; j < allArticleTitles[i].length; j++) { + newNumbers++; + + } + } + return Math.round(newNumbers / allArticleTitles.length); + }