From 6c893eeaad0c9915477fe3972a14074cda2d8dd5 Mon Sep 17 00:00:00 2001 From: Abdennour Hachemi Date: Thu, 18 Jun 2020 05:41:59 +0100 Subject: [PATCH 01/65] Update pull_request_template.md --- .github/pull_request_template.md | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/.github/pull_request_template.md b/.github/pull_request_template.md index 696fd85..8c3a067 100644 --- a/.github/pull_request_template.md +++ b/.github/pull_request_template.md @@ -1,10 +1,10 @@ # Your Details -Your Name: -Your City: -Your Slack Name: +Your Name:Abdennour Hachemi +Your City:Birmingham +Your Slack Name:nouri89 # Homework Details -Module: -Week: +Module:javaScript +Week:1 From 5189eb24ad0f488cdb84187653da4ed5138422a7 Mon Sep 17 00:00:00 2001 From: Abdennour Hachemi Date: Thu, 18 Jun 2020 09:14:56 +0100 Subject: [PATCH 02/65] testing the console --- week-1/1-exercises/B-hello-world/exercise.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/week-1/1-exercises/B-hello-world/exercise.js b/week-1/1-exercises/B-hello-world/exercise.js index b179ee9..6f2e311 100644 --- a/week-1/1-exercises/B-hello-world/exercise.js +++ b/week-1/1-exercises/B-hello-world/exercise.js @@ -1 +1,3 @@ -console.log("Hello world"); +console.log('Hello world. i have just started learning javaScript.' + 4 + ` testing the new methode over ${24} hours`); + +console.log(1); From 756cf5df0b5943a4b46fee0a36690bfa0f35c1b8 Mon Sep 17 00:00:00 2001 From: Abdennour Hachemi Date: Thu, 18 Jun 2020 09:18:18 +0100 Subject: [PATCH 03/65] printing Hello world three times --- week-1/1-exercises/C-variables/exercise.js | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/week-1/1-exercises/C-variables/exercise.js b/week-1/1-exercises/C-variables/exercise.js index a6bbb97..40c6ca0 100644 --- a/week-1/1-exercises/C-variables/exercise.js +++ b/week-1/1-exercises/C-variables/exercise.js @@ -1,3 +1,4 @@ -// Start by creating a variable `greeting` - -console.log(greeting); +let greeting = 'Hello World'; +for (i = 0; i < 3; i++) { + console.log(greeting); +} From 6dc1425f6e4ae109356f5120e6f6a9d6470260ab Mon Sep 17 00:00:00 2001 From: Abdennour Hachemi Date: Fri, 19 Jun 2020 22:29:52 +0100 Subject: [PATCH 04/65] solve exercise D --- week-1/1-exercises/D-strings/exercise.js | 1 + 1 file changed, 1 insertion(+) diff --git a/week-1/1-exercises/D-strings/exercise.js b/week-1/1-exercises/D-strings/exercise.js index 2cffa6a..62c6f8c 100644 --- a/week-1/1-exercises/D-strings/exercise.js +++ b/week-1/1-exercises/D-strings/exercise.js @@ -1,3 +1,4 @@ // Start by creating a variable `message` +let message = "This is a string \nString"; console.log(message); From d923411484987d9b7102214f6cc0264271a57da0 Mon Sep 17 00:00:00 2001 From: Abdennour Hachemi Date: Fri, 19 Jun 2020 22:46:52 +0100 Subject: [PATCH 05/65] solving exercise D --- week-1/1-exercises/D-strings/exercise.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/week-1/1-exercises/D-strings/exercise.js b/week-1/1-exercises/D-strings/exercise.js index 62c6f8c..02ec126 100644 --- a/week-1/1-exercises/D-strings/exercise.js +++ b/week-1/1-exercises/D-strings/exercise.js @@ -1,4 +1,4 @@ -// Start by creating a variable `message` -let message = "This is a string \nString"; +let message = 'Learning javaScript is Fun '; +let myMessage = typeof message; -console.log(message); +console.log(`${message} \n${myMessage}`); From b9d74006f6b4abcc3cb7f2286ac0aca2e9580f86 Mon Sep 17 00:00:00 2001 From: Abdennour Hachemi Date: Fri, 19 Jun 2020 22:49:19 +0100 Subject: [PATCH 06/65] solving exercise E --- week-1/1-exercises/E-strings-concatenation/exercise.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/week-1/1-exercises/E-strings-concatenation/exercise.js b/week-1/1-exercises/E-strings-concatenation/exercise.js index 2cffa6a..ddda811 100644 --- a/week-1/1-exercises/E-strings-concatenation/exercise.js +++ b/week-1/1-exercises/E-strings-concatenation/exercise.js @@ -1,3 +1,5 @@ -// Start by creating a variable `message` + let greeting = "Hello, my name is "; + let myName = "Abdennour"; + let message = greeting + myName; -console.log(message); + console.log(message); From 9a6edf66e90339e2870e63743040b51f6e4d38a6 Mon Sep 17 00:00:00 2001 From: Abdennour Hachemi Date: Fri, 19 Jun 2020 22:56:13 +0100 Subject: [PATCH 07/65] solving excercise1 --- week-1/1-exercises/F-strings-methods/exercise.js | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/week-1/1-exercises/F-strings-methods/exercise.js b/week-1/1-exercises/F-strings-methods/exercise.js index 2cffa6a..997f64b 100644 --- a/week-1/1-exercises/F-strings-methods/exercise.js +++ b/week-1/1-exercises/F-strings-methods/exercise.js @@ -1,3 +1,8 @@ // Start by creating a variable `message` - +var myName = "Abdennour"; +var myNameLowerCase=myName.toLowerCase(); +var myNameLength = myName.length; +var message = + "My Name is "+ myName+" and iss " + myNameLength + " Characters Long."; console.log(message); +console.log(myNameLowerCase); From 4a7c672fc2c12ed7e8ef4f82740c59ef7376f71f Mon Sep 17 00:00:00 2001 From: Abdennour Hachemi Date: Fri, 19 Jun 2020 23:00:06 +0100 Subject: [PATCH 08/65] solving exercise --- week-1/1-exercises/F-strings-methods/exercise2.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/week-1/1-exercises/F-strings-methods/exercise2.js b/week-1/1-exercises/F-strings-methods/exercise2.js index b4b4694..c6eca72 100644 --- a/week-1/1-exercises/F-strings-methods/exercise2.js +++ b/week-1/1-exercises/F-strings-methods/exercise2.js @@ -1,3 +1,6 @@ -const name = " Daniel "; +const name = " Daniel ".trim(); +let nameLength = name.length; +var message = + "My Name is " + name + "and is " + nameLength + " Characters Long."; console.log(message); From f00e0337211411df419683f7b585521b8385e708 Mon Sep 17 00:00:00 2001 From: Abdennour Hachemi Date: Fri, 19 Jun 2020 23:05:00 +0100 Subject: [PATCH 09/65] solve exercise G --- week-1/1-exercises/G-numbers/exercise.js | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/week-1/1-exercises/G-numbers/exercise.js b/week-1/1-exercises/G-numbers/exercise.js index 49e7bc0..6a25180 100644 --- a/week-1/1-exercises/G-numbers/exercise.js +++ b/week-1/1-exercises/G-numbers/exercise.js @@ -1 +1,9 @@ // Start by creating a variables `numberOfStudents` and `numberOfMentors` +var numberOfStudents = 15; +var numberOfMentors = 8; +console.log( + `Number of students: ${numberOfStudents}\nNumber of mentors: ${numberOfMentors}\nTotal number of students and mentors: ${ + numberOfStudents + numberOfMentors + }` +); + From ecf75a657414a8a4443c5d4ccb238e01c24f85ea Mon Sep 17 00:00:00 2001 From: Abdennour Hachemi Date: Fri, 19 Jun 2020 23:06:22 +0100 Subject: [PATCH 10/65] solving float exercise --- week-1/1-exercises/I-floats/exercise.js | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/week-1/1-exercises/I-floats/exercise.js b/week-1/1-exercises/I-floats/exercise.js index a5bbcd8..d4181f3 100644 --- a/week-1/1-exercises/I-floats/exercise.js +++ b/week-1/1-exercises/I-floats/exercise.js @@ -1,2 +1,20 @@ var numberOfStudents = 15; var numberOfMentors = 8; +/* Using the variables provided in the exercise calculate the percentage of mentors and students in the group + +## Expected result + +``` +Percentage students: 65% +Percentage mentors: 35%*/ +var numberOfStudents = 15; +var numberOfStudents = 15; +var studentsPercentage = Math.round( + (numberOfStudents / (numberOfStudents + numberOfMentors)) * 100 +); +var numberOfMentors = 8; +var mentorsPercentage = Math.round( + (numberOfMentors / (numberOfStudents + numberOfMentors)) * 100 +); +console.log(`Percentage students: ${studentsPercentage}%`); +console.log(`Percentage mentors: ${mentorsPercentage}%`); From b3c20c537ac82dd1190e373627543c70cbfafe81 Mon Sep 17 00:00:00 2001 From: Abdennour Hachemi Date: Fri, 19 Jun 2020 23:07:52 +0100 Subject: [PATCH 11/65] solving exercise --- week-1/1-exercises/J-functions/exercise.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/week-1/1-exercises/J-functions/exercise.js b/week-1/1-exercises/J-functions/exercise.js index 0ae5850..e36df72 100644 --- a/week-1/1-exercises/J-functions/exercise.js +++ b/week-1/1-exercises/J-functions/exercise.js @@ -1,7 +1,10 @@ function halve(number) { - // complete the function here + + return number / 2; } var result = halve(12); console.log(result); +console.log(halve(111)); +console.log(halve(20.5)); From 7d84ec7bc64c88a2f30316f37955c0dbe8c464e7 Mon Sep 17 00:00:00 2001 From: Abdennour Hachemi Date: Fri, 19 Jun 2020 23:09:02 +0100 Subject: [PATCH 12/65] solving Function exercise --- week-1/1-exercises/J-functions/exercise2.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/week-1/1-exercises/J-functions/exercise2.js b/week-1/1-exercises/J-functions/exercise2.js index 82ef5e7..54ca144 100644 --- a/week-1/1-exercises/J-functions/exercise2.js +++ b/week-1/1-exercises/J-functions/exercise2.js @@ -1,5 +1,5 @@ function triple(number) { - // complete function here + return number * 3; } var result = triple(12); From fa1e45c448d725c1e7d2be3e740d5f633d87a31e Mon Sep 17 00:00:00 2001 From: Abdennour Hachemi Date: Fri, 19 Jun 2020 23:10:29 +0100 Subject: [PATCH 13/65] solve exercise --- week-1/1-exercises/K-functions-parameters/exercise.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/week-1/1-exercises/K-functions-parameters/exercise.js b/week-1/1-exercises/K-functions-parameters/exercise.js index 8d5db5e..c618777 100644 --- a/week-1/1-exercises/K-functions-parameters/exercise.js +++ b/week-1/1-exercises/K-functions-parameters/exercise.js @@ -1,5 +1,7 @@ // Complete the function so that it takes input parameters -function multiply() { +function multiply(a,b) { + var multiple= a*b; + return multiple; // Calculate the result of the function and return it } From 4e50e826ccf03e87b2998d41f768d7fda49cd3fa Mon Sep 17 00:00:00 2001 From: Abdennour Hachemi Date: Fri, 19 Jun 2020 23:12:04 +0100 Subject: [PATCH 14/65] solve exercise --- week-1/1-exercises/K-functions-parameters/exercise2.js | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/week-1/1-exercises/K-functions-parameters/exercise2.js b/week-1/1-exercises/K-functions-parameters/exercise2.js index db7a890..5cee723 100644 --- a/week-1/1-exercises/K-functions-parameters/exercise2.js +++ b/week-1/1-exercises/K-functions-parameters/exercise2.js @@ -1,4 +1,8 @@ // Declare your function first +function divide(a,b){ + var division=a/b; + return division; +} var result = divide(3, 4); From fd04331d87a0ff2065963a5de5cb35cb3dc717c8 Mon Sep 17 00:00:00 2001 From: Abdennour Hachemi Date: Fri, 19 Jun 2020 23:13:28 +0100 Subject: [PATCH 15/65] update exercise --- week-1/1-exercises/K-functions-parameters/exercise3.js | 3 +++ 1 file changed, 3 insertions(+) diff --git a/week-1/1-exercises/K-functions-parameters/exercise3.js b/week-1/1-exercises/K-functions-parameters/exercise3.js index 537e9f4..5fe983d 100644 --- a/week-1/1-exercises/K-functions-parameters/exercise3.js +++ b/week-1/1-exercises/K-functions-parameters/exercise3.js @@ -1,4 +1,7 @@ // Write your function here +function createGreeting(name){ + return `Hello, my name is ${name}` +} var greeting = createGreeting("Daniel"); From 75a7612b5c46c69e987a23c9d690286fda361da4 Mon Sep 17 00:00:00 2001 From: Abdennour Hachemi Date: Fri, 19 Jun 2020 23:14:30 +0100 Subject: [PATCH 16/65] solve exercise4.js --- week-1/1-exercises/K-functions-parameters/exercise4.js | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/week-1/1-exercises/K-functions-parameters/exercise4.js b/week-1/1-exercises/K-functions-parameters/exercise4.js index 7ab4458..a17bb1e 100644 --- a/week-1/1-exercises/K-functions-parameters/exercise4.js +++ b/week-1/1-exercises/K-functions-parameters/exercise4.js @@ -1,5 +1,9 @@ // Declare your function first +function addition(num1, num2) { + let result = num1 + num2; + return result; +} // Call the function and assign to a variable `sum` - +let sum = addition(13, 124); console.log(sum); From 71490ad67d2753ce93ec7cc75c5d3ead5c2d207b Mon Sep 17 00:00:00 2001 From: Abdennour Hachemi Date: Fri, 19 Jun 2020 23:15:45 +0100 Subject: [PATCH 17/65] Solve exercise5.js --- .../1-exercises/K-functions-parameters/exercise5.js | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/week-1/1-exercises/K-functions-parameters/exercise5.js b/week-1/1-exercises/K-functions-parameters/exercise5.js index 7c5bcd6..64c7d2c 100644 --- a/week-1/1-exercises/K-functions-parameters/exercise5.js +++ b/week-1/1-exercises/K-functions-parameters/exercise5.js @@ -1,4 +1,16 @@ // Declare your function here +/* * Write a function that takes a name (a string) and an age (a number) and returns a greeting (a string) + +## Expected result + +``` +Hello, my name is Daniel and I'm 30 years old +``` + */ +function createLongGreeting(string, num) { + let greet = `Hello, my name is ${string} and I'm ${num} years old `; + return greet; +} const greeting = createLongGreeting("Daniel", 30); From 6aa1514b56928c398653c08c2089bbd23a3ca44b Mon Sep 17 00:00:00 2001 From: Abdennour Hachemi Date: Fri, 19 Jun 2020 23:17:45 +0100 Subject: [PATCH 18/65] sove exercise L --- .../L-functions-nested/exercise.js | 29 +++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/week-1/1-exercises/L-functions-nested/exercise.js b/week-1/1-exercises/L-functions-nested/exercise.js index a5d3774..a54bfc3 100644 --- a/week-1/1-exercises/L-functions-nested/exercise.js +++ b/week-1/1-exercises/L-functions-nested/exercise.js @@ -3,3 +3,32 @@ var mentor2 = "Irina"; var mentor3 = "Mimi"; var mentor4 = "Rob"; var mentor5 = "Yohannes"; +var students = 15; +var mentors = 8; +function percentage(calculatePercentage) { + var percent = Math.round((calculatePercentage / (students + mentors)) * 100); + return percent; +} + +function message() { + console.log( + `Percentage Mentors: ${percentage( + students + )}%\nPercentage mentors: ${percentage(mentors)}%` + ); +} +message(); +/* In `exercise2.js` you have been provided with the names of some mentors. Write a program that logs a shouty greeting to each one. +- Your program should include a function that spells their name in uppercase, and a function that creates a shouty greeting. +- Log each greeting to the console. */ +function upperCase(name) { + mentorName = name.toUpperCase(); + return mentorName; +} +mentors = [mentor1, mentor2, mentor3, mentor3, mentor4, mentor5]; +function greeting() { + for (i = 0; i < 5; i++) { + console.log(`HEllO ${upperCase(mentors[i])}`); + } +} +greeting(); From 3626e06494d49ca0afe2f1509f720aa110dfe742 Mon Sep 17 00:00:00 2001 From: Abdennour Hachemi Date: Fri, 19 Jun 2020 23:21:23 +0100 Subject: [PATCH 19/65] Solving currency conversion exercise --- week-1/3-extra/1-currency-conversion.js | 32 +++++++++++++++++-------- 1 file changed, 22 insertions(+), 10 deletions(-) diff --git a/week-1/3-extra/1-currency-conversion.js b/week-1/3-extra/1-currency-conversion.js index 7f321d9..cd11196 100644 --- a/week-1/3-extra/1-currency-conversion.js +++ b/week-1/3-extra/1-currency-conversion.js @@ -5,7 +5,10 @@ Write a function that converts a price to USD (exchange rate is 1.4 $ to £) */ -function convertToUSD() {} +function convertToUSD(AmountToConvert) { + var usDollarEquivlent = AmountToConvert * 1.4; + return usDollarEquivlent; //.toFixed(2); +} /* CURRENCY FORMATTING @@ -16,7 +19,16 @@ function convertToUSD() {} Find a way to add 1% to all currency conversions (think about the DRY principle) */ -function convertToBRL() {} +function convertToBRL(AmountToConvert) { + var realBrazilianEquivlent = AmountToConvert * 5.7; + realBrazilianEquivlent = addOnePercentFee(realBrazilianEquivlent); + return realBrazilianEquivlent; //.toFixed(2); +} +function addOnePercentFee(transactionAmount) { + var fee = transactionAmount * 0.01; + transactionPlusFee = transactionAmount + fee; + return transactionPlusFee; +} /* ======= TESTS - DO NOT MODIFY ===== There are some Tests in this file that will help you work out if your code is working. @@ -25,14 +37,14 @@ To run these tests type `node 1-currency-conversion` into your terminal */ function test(test_name, expr) { - let status; - if (expr) { - status = "PASSED"; - } else { - status = "FAILED"; - } - - console.log(`${test_name}: ${status}`); + let status; + if (expr) { + status = "PASSED"; + } else { + status = "FAILED"; + } + + console.log(`${test_name}: ${status}`); } test("convertToUSD function works", convertToUSD(32) === 44.8); From 7cfd051406e59d80fd1fcf52a9e0835d66bed5aa Mon Sep 17 00:00:00 2001 From: Abdennour Hachemi Date: Fri, 19 Jun 2020 23:23:13 +0100 Subject: [PATCH 20/65] solve piping exercise --- week-1/3-extra/2-piping.js | 52 ++++++++++++++++++++------------------ 1 file changed, 28 insertions(+), 24 deletions(-) diff --git a/week-1/3-extra/2-piping.js b/week-1/3-extra/2-piping.js index 93c0bf7..c93566f 100644 --- a/week-1/3-extra/2-piping.js +++ b/week-1/3-extra/2-piping.js @@ -16,26 +16,30 @@ the final result to the variable goodCode */ -function add() { - +function add(x, y) { + let sum = (x * 10 + y * 10) / 10; + return sum; } - -function multiply() { - +console.log(add(2.4, 5.3)); +function multiply(x, y) { + let multiple = x * y; + return multiple; } -function format() { - +function format(number) { + return `£${number}`; } -const startingValue = 2 +const startingValue = 2; // Why can this code be seen as bad practice? Comment your answer. -let badCode = +let badCode = format(multiply(add(startingValue, 10), 2)); /* BETTER PRACTICE */ -let goodCode = +let goodCode = add(startingValue, 10); +goodCode = multiply(goodCode, 2); +goodCode = format(goodCode); /* ======= TESTS - DO NOT MODIFY ===== There are some Tests in this file that will help you work out if your code is working. @@ -44,19 +48,19 @@ To run these tests type `node 2-piping.js` into your terminal */ function test(test_name, expr) { - let status; - if (expr) { - status = "PASSED" - } else { - status = "FAILED" - } - - console.log(`${test_name}: ${status}`) + let status; + if (expr) { + status = "PASSED"; + } else { + status = "FAILED"; + } + + console.log(`${test_name}: ${status}`); } -test('add function - case 1 works', add(1,3) === 4) -test('add function - case 2 works', add(2.4,5.3) === 7.7) -test('multiply function works', multiply(2,3) === 6) -test('format function works', format(16) === "£16") -test('badCode variable correctly assigned', badCode === "£24") -test('goodCode variable correctly assigned', goodCode === "£24") \ No newline at end of file +test("add function - case 1 works", add(1, 3) === 4); +test("add function - case 2 works", add(2.4, 5.3) === 7.7); +test("multiply function works", multiply(2, 3) === 6); +test("format function works", format(16) === "£16"); +test("badCode variable correctly assigned", badCode === "£24"); +test("goodCode variable correctly assigned", goodCode === "£24"); From d648fd95d7077f8078dd6f644d9393dca5daa3a0 Mon Sep 17 00:00:00 2001 From: Abdennour Hachemi Date: Thu, 25 Jun 2020 16:51:44 +0100 Subject: [PATCH 21/65] mark as done --- week-2/0-freecodecamp/0-freecodecamp.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/week-2/0-freecodecamp/0-freecodecamp.md b/week-2/0-freecodecamp/0-freecodecamp.md index b21a59a..7a02c44 100644 --- a/week-2/0-freecodecamp/0-freecodecamp.md +++ b/week-2/0-freecodecamp/0-freecodecamp.md @@ -1,4 +1,4 @@ -## FreeCodeCamp +## FreeCodeCamp done If you haven't already, you should complete all of these lessons on FreeCodeCamp - https://www.freecodecamp.org/learn From 5c71bac4d2e7a15a45dc56b30979618fdfe9bee8 Mon Sep 17 00:00:00 2001 From: Abdennour Hachemi Date: Thu, 25 Jun 2020 17:08:52 +0100 Subject: [PATCH 22/65] Mark as done --- week-2/1-exercises/A-expressions/README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/week-2/1-exercises/A-expressions/README.md b/week-2/1-exercises/A-expressions/README.md index 9503b6b..0dadf8b 100644 --- a/week-2/1-exercises/A-expressions/README.md +++ b/week-2/1-exercises/A-expressions/README.md @@ -1,3 +1,4 @@ +/***********************DONE***************************************************************/ In JavaScript there are **expressions** and **statements**. We will use these words frequently to describe code. ### Expression From 4526f42e3cae8221dbdc4df6532275b9a79409c4 Mon Sep 17 00:00:00 2001 From: Abdennour Hachemi Date: Thu, 25 Jun 2020 17:10:44 +0100 Subject: [PATCH 23/65] Complete Exercise --- week-2/1-exercises/B-boolean-literals/exercise.js | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/week-2/1-exercises/B-boolean-literals/exercise.js b/week-2/1-exercises/B-boolean-literals/exercise.js index 6c5060f..1d2d6a3 100644 --- a/week-2/1-exercises/B-boolean-literals/exercise.js +++ b/week-2/1-exercises/B-boolean-literals/exercise.js @@ -6,15 +6,18 @@ */ var codeYourFutureIsGreat = true; +var mozafarIsCool = false; +var calculationCorrect = true; +var moreThan10Students = false; /* DO NOT EDIT BELOW THIS LINE --------------------------- */ -console.log("Is Code Your Future great?", codeYourFutureIsGreat); -console.log("Is Mozafar cool?", mozafarIsCool); -console.log("Does 1 + 1 = 2?", calculationCorrect); -console.log("Are there more than 10 students?", moreThan10Students); +console.log('Is Code Your Future great?', codeYourFutureIsGreat); +console.log('Is Mozafar cool?', mozafarIsCool); +console.log('Does 1 + 1 = 2?', calculationCorrect); +console.log('Are there more than 10 students?', moreThan10Students); /* EXPECTED RESULT From 1eedd9c48fc2fb7d1e99fbbb46f6b39f22f67191 Mon Sep 17 00:00:00 2001 From: Abdennour Hachemi Date: Thu, 25 Jun 2020 17:12:04 +0100 Subject: [PATCH 24/65] Complete Comparison exercise --- week-2/1-exercises/C-comparison-operators/exercise.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/week-2/1-exercises/C-comparison-operators/exercise.js b/week-2/1-exercises/C-comparison-operators/exercise.js index 58aee1c..959475c 100644 --- a/week-2/1-exercises/C-comparison-operators/exercise.js +++ b/week-2/1-exercises/C-comparison-operators/exercise.js @@ -7,14 +7,14 @@ var studentCount = 16; var mentorCount = 9; -var moreStudentsThanMentors; // finish this statement +var moreStudentsThanMentors= studentCount>mentorCount; // finish this statement var roomMaxCapacity = 25; -var enoughSpaceInRoom; // finish this statement +var enoughSpaceInRoom=roomMaxCapacity>=(studentCount+mentorCount); // finish this statement var personA = "Daniel"; var personB = "Irina"; -var sameName; // finish this statement +var sameName=personA===personB; // finish this statement /* DO NOT EDIT BELOW THIS LINE From 6f848d3c5abbda25a35e14d741c714264838cb12 Mon Sep 17 00:00:00 2001 From: Abdennour Hachemi Date: Thu, 25 Jun 2020 17:13:10 +0100 Subject: [PATCH 25/65] Complete Predicates exercise --- week-2/1-exercises/D-predicates/exercise.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/week-2/1-exercises/D-predicates/exercise.js b/week-2/1-exercises/D-predicates/exercise.js index f600521..7d0c074 100644 --- a/week-2/1-exercises/D-predicates/exercise.js +++ b/week-2/1-exercises/D-predicates/exercise.js @@ -7,12 +7,13 @@ // Finish the predicate function to test if the passed number is negative (less than zero) function isNegative(number) { + return number<0; } // Finish the predicate function to test if the passed number is between 0 and 10 function isBetweenZeroAnd10(number) { - + return (number >= 0 && number <=10) ; } /* From 3cdf839b71ba5232f848e71d26e43e45a4c0919c Mon Sep 17 00:00:00 2001 From: Abdennour Hachemi Date: Thu, 25 Jun 2020 17:14:57 +0100 Subject: [PATCH 26/65] Complete conditional exercise --- week-2/1-exercises/E-conditionals/exercise.js | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/week-2/1-exercises/E-conditionals/exercise.js b/week-2/1-exercises/E-conditionals/exercise.js index acbaaa8..0b76162 100644 --- a/week-2/1-exercises/E-conditionals/exercise.js +++ b/week-2/1-exercises/E-conditionals/exercise.js @@ -6,8 +6,13 @@ If Daniel is a student, print out "Hi, I'm Daniel, I'm a student." */ -var name = "Daniel"; -var danielsRole = "mentor"; +var name = 'Daniel'; +var danielsRole = 'mentor'; +if (danielsRole === 'mentor') { + console.log(`Hi, I'm ${name}, I'm a mentor.`); +} else if (danielsRole === 'stuent') { + console.log(`Hi, I'm ${name}, I'm a ${danielsRole}.`); +} /* EXPECTED RESULT From 635eaaf1456d1fde05789731741fa193b802f101 Mon Sep 17 00:00:00 2001 From: Abdennour Hachemi Date: Thu, 25 Jun 2020 17:16:16 +0100 Subject: [PATCH 27/65] complete logical exercise --- week-2/1-exercises/F-logical-operators/exercise.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/week-2/1-exercises/F-logical-operators/exercise.js b/week-2/1-exercises/F-logical-operators/exercise.js index a8f2945..4c27024 100644 --- a/week-2/1-exercises/F-logical-operators/exercise.js +++ b/week-2/1-exercises/F-logical-operators/exercise.js @@ -11,14 +11,14 @@ var cssLevel = 4; // Finish the statement to check whether HTML, CSS knowledge are above 5 // (hint: use the comparison operator from before) -var htmlLevelAbove5; -var cssLevelAbove5; +var htmlLevelAbove5 =htmlLevel>5; +var cssLevelAbove5=cssLevel>5; // Finish the next two statement // Use the previous variables and logical operators // Do not "hardcode" the answers -var cssAndHtmlAbove5; -var cssOrHtmlAbove5; +var cssAndHtmlAbove5=htmlLevelAbove5 && cssLevelAbove5 >5; +var cssOrHtmlAbove5=htmlLevelAbove5 || cssLevelAbove5 >5; /* DO NOT EDIT BELOW THIS LINE From b3069f62183443945ae31ae46840ecdd83517023 Mon Sep 17 00:00:00 2001 From: Abdennour Hachemi Date: Thu, 25 Jun 2020 17:17:16 +0100 Subject: [PATCH 28/65] complete logical exercise2 --- .../F-logical-operators/exercise2.js | 26 ++++++++++++++----- 1 file changed, 19 insertions(+), 7 deletions(-) diff --git a/week-2/1-exercises/F-logical-operators/exercise2.js b/week-2/1-exercises/F-logical-operators/exercise2.js index 6f4199c..387c946 100644 --- a/week-2/1-exercises/F-logical-operators/exercise2.js +++ b/week-2/1-exercises/F-logical-operators/exercise2.js @@ -5,17 +5,29 @@ Update the code so that you get the expected result. */ -function isNegative() {} - +function isNegative(num) { + return num < 0; +} +function isBetween5and10(num) { + return num >= 0 && num <= 10; +} +function isShortName(name) { + if (name.length <= 6) return true; + else return false; +} +function startsWithD(name) { + if (x.charAt(0) === 'D') return true; + else return false; +} /* DO NOT EDIT BELOW THIS LINE --------------------------- */ -console.log("Is -10 is a negative number?", isNegative(-10)); -console.log("Is 5 a negative number?", isNegative(5)); -console.log("Is 10 in the range 5-10?", isBetween5and10(10)); -console.log("Is Daniel a short name?", isShortName("Daniel")); -console.log("Does Daniel start with 'D'?", startsWithD("Daniel")); +console.log('Is -10 is a negative number?', isNegative(-10)); +console.log('Is 5 a negative number?', isNegative(5)); +console.log('Is 10 in the range 5-10?', isBetween5and10(10)); +console.log('Is Daniel a short name?', isShortName('Daniel')); +console.log("Does Daniel start with 'D'?", startsWithD('Daniel')); /* EXPECTED RESULT From 8e260a4477ecd7489c6cb12806ca6d97e397c39d Mon Sep 17 00:00:00 2001 From: Abdennour Hachemi Date: Thu, 25 Jun 2020 17:20:20 +0100 Subject: [PATCH 29/65] Update exercise-1.js --- week-2/1-exercises/G-conditionals-2/exercise-1.js | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/week-2/1-exercises/G-conditionals-2/exercise-1.js b/week-2/1-exercises/G-conditionals-2/exercise-1.js index 54708ef..0b851e0 100644 --- a/week-2/1-exercises/G-conditionals-2/exercise-1.js +++ b/week-2/1-exercises/G-conditionals-2/exercise-1.js @@ -7,7 +7,11 @@ */ function negativeOrPositive(number) { - + if (number < 0) { + return 'negative'; + } else if (number >= 0) { + return 'positive'; + } } /* @@ -17,9 +21,9 @@ var number1 = 5; var number2 = -1; var number3 = 0; -console.log(number1 + " is " + negativeOrPositive(number1)); -console.log(number2 + " is " + negativeOrPositive(number2)); -console.log(number3 + " is " + negativeOrPositive(number3)); +console.log(number1 + ' is ' + negativeOrPositive(number1)); +console.log(number2 + ' is ' + negativeOrPositive(number2)); +console.log(number3 + ' is ' + negativeOrPositive(number3)); /* EXPECTED RESULT From 9c603f566d07cd0bb98d2d793fecbf7e7292653a Mon Sep 17 00:00:00 2001 From: Abdennour Hachemi Date: Thu, 25 Jun 2020 17:28:34 +0100 Subject: [PATCH 30/65] Solve Exercise2 --- week-2/1-exercises/G-conditionals-2/exercise-2.js | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/week-2/1-exercises/G-conditionals-2/exercise-2.js b/week-2/1-exercises/G-conditionals-2/exercise-2.js index 313f3fb..0c9b590 100644 --- a/week-2/1-exercises/G-conditionals-2/exercise-2.js +++ b/week-2/1-exercises/G-conditionals-2/exercise-2.js @@ -8,7 +8,8 @@ */ function studentPassed(grade) { - + if (grade < 50) return 'failed'; + else if (grade >= 50) return 'passed'; } /* @@ -18,9 +19,9 @@ var grade1 = 49; var grade2 = 50; var grade3 = 100; -console.log("'" + grade1 + "': " + studentPassed(grade1)) -console.log("'" + grade2 + "': " + studentPassed(grade2)) -console.log("'" + grade3 + "': " + studentPassed(grade3)) +console.log("'" + grade1 + "': " + studentPassed(grade1)); +console.log("'" + grade2 + "': " + studentPassed(grade2)); +console.log("'" + grade3 + "': " + studentPassed(grade3)); /* EXPECTED RESULT From 3a801d868678055bad3dbbfe59012acd495e9c68 Mon Sep 17 00:00:00 2001 From: Abdennour Hachemi Date: Thu, 25 Jun 2020 17:29:31 +0100 Subject: [PATCH 31/65] Solve exercise 3 --- week-2/1-exercises/G-conditionals-2/exercise-3.js | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/week-2/1-exercises/G-conditionals-2/exercise-3.js b/week-2/1-exercises/G-conditionals-2/exercise-3.js index a79cf30..97b3318 100644 --- a/week-2/1-exercises/G-conditionals-2/exercise-3.js +++ b/week-2/1-exercises/G-conditionals-2/exercise-3.js @@ -9,7 +9,15 @@ */ function calculateGrade(mark) { - + if (mark >= 80) { + return 'A'; + } else if (mark < 80 && mark > 60) { + return 'B'; + } else if (mark <= 60 && mark >= 50) { + return 'C'; + } else { + return 'F'; + } } /* @@ -25,7 +33,7 @@ console.log("'" + grade2 + "': " + calculateGrade(grade2)); console.log("'" + grade3 + "': " + calculateGrade(grade3)); console.log("'" + grade4 + "': " + calculateGrade(grade4)); - /* +/* EXPECTED RESULT --------------- '49': F From 8ca4cfceebd7c0cb5c29e4e2277dc17a77c0a0ef Mon Sep 17 00:00:00 2001 From: Abdennour Hachemi Date: Thu, 25 Jun 2020 17:31:06 +0100 Subject: [PATCH 32/65] Solve exercise4 --- .../1-exercises/G-conditionals-2/exercise-4.js | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/week-2/1-exercises/G-conditionals-2/exercise-4.js b/week-2/1-exercises/G-conditionals-2/exercise-4.js index bd5bb1e..a2b8f35 100644 --- a/week-2/1-exercises/G-conditionals-2/exercise-4.js +++ b/week-2/1-exercises/G-conditionals-2/exercise-4.js @@ -9,21 +9,23 @@ */ function containsCode(sentence) { - + if (sentence.search('code') === -1) { + return false; + } else return true; } /* DO NOT EDIT BELOW THIS LINE --------------------------- */ -var sentence1 = "code your future"; -var sentence2 = "draw your future"; -var sentence3 = "design your future"; +var sentence1 = 'code your future'; +var sentence2 = 'draw your future'; +var sentence3 = 'design your future'; -console.log("'" + sentence1 + "': " + containsCode(sentence1)) -console.log("'" + sentence2 + "': " + containsCode(sentence2)) -console.log("'" + sentence3 + "': " + containsCode(sentence3)) +console.log("'" + sentence1 + "': " + containsCode(sentence1)); +console.log("'" + sentence2 + "': " + containsCode(sentence2)); +console.log("'" + sentence3 + "': " + containsCode(sentence3)); - /* +/* EXPECTED RESULT --------------- 'code your future': true From dd837fee6b5873368822da72672441ceef4abb97 Mon Sep 17 00:00:00 2001 From: Abdennour Hachemi Date: Thu, 25 Jun 2020 17:34:06 +0100 Subject: [PATCH 33/65] solve array exercise --- week-2/1-exercises/H-array-literals/exercise.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/week-2/1-exercises/H-array-literals/exercise.js b/week-2/1-exercises/H-array-literals/exercise.js index d6dc556..99500cc 100644 --- a/week-2/1-exercises/H-array-literals/exercise.js +++ b/week-2/1-exercises/H-array-literals/exercise.js @@ -6,7 +6,8 @@ var numbers = []; // add numbers from 1 to 10 into this array var mentors; // Create an array with the names of the mentors: Daniel, Irina and Rares - +numbers = [ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 ]; +mentors = [ 'Daniel', 'Irina', 'Rares' ]; /* DO NOT EDIT BELOW THIS LINE --------------------------- */ From 952cc2c96d9aec2ac2c1536b9d52055c7684986d Mon Sep 17 00:00:00 2001 From: Abdennour Hachemi Date: Thu, 25 Jun 2020 17:34:31 +0100 Subject: [PATCH 34/65] solve array exercise From 929fd83e080a2e82914ea20e48c1f8a196b4b55a Mon Sep 17 00:00:00 2001 From: Abdennour Hachemi Date: Thu, 25 Jun 2020 17:41:02 +0100 Subject: [PATCH 35/65] solve array exercsie --- week-2/1-exercises/I-array-properties/exercise.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/week-2/1-exercises/I-array-properties/exercise.js b/week-2/1-exercises/I-array-properties/exercise.js index f9aec89..420f75a 100644 --- a/week-2/1-exercises/I-array-properties/exercise.js +++ b/week-2/1-exercises/I-array-properties/exercise.js @@ -6,13 +6,13 @@ */ function isEmpty(arr) { - return; // complete this statement + return arr.length === 0; // complete this statement } /* DO NOT EDIT BELOW THIS LINE --------------------------- */ -var numbers = [1, 2, 3]; +var numbers = [ 1, 2, 3 ]; var names = []; console.log(isEmpty(numbers)); From fa65fda573c16d0fa48d3b2ee6ca19afaa9f2847 Mon Sep 17 00:00:00 2001 From: Abdennour Hachemi Date: Thu, 25 Jun 2020 17:46:43 +0100 Subject: [PATCH 36/65] solve exercise --- week-2/1-exercises/J-array-get-set/exercise.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/week-2/1-exercises/J-array-get-set/exercise.js b/week-2/1-exercises/J-array-get-set/exercise.js index 3b95694..2e397b5 100644 --- a/week-2/1-exercises/J-array-get-set/exercise.js +++ b/week-2/1-exercises/J-array-get-set/exercise.js @@ -5,18 +5,18 @@ */ function first(arr) { - return; // complete this statement + return arr[0]; // complete this statement } function last(arr) { - return; // complete this statement + return arr[arr.length - 1]; // complete this statement } /* DO NOT EDIT BELOW THIS LINE --------------------------- */ -var numbers = [1, 2, 3]; -var names = ["Irina", "Ashleigh", "Mozafar", "Joe"]; +var numbers = [ 1, 2, 3 ]; +var names = [ 'Irina', 'Ashleigh', 'Mozafar', 'Joe' ]; console.log(first(numbers)); console.log(last(numbers)); From f9f74daeeae76dee85d0f7ef39eea8680f12d751 Mon Sep 17 00:00:00 2001 From: Abdennour Hachemi Date: Thu, 25 Jun 2020 17:48:28 +0100 Subject: [PATCH 37/65] solve exercise 2 --- week-2/1-exercises/J-array-get-set/exercises2.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/week-2/1-exercises/J-array-get-set/exercises2.js b/week-2/1-exercises/J-array-get-set/exercises2.js index 97f126f..1c0faef 100644 --- a/week-2/1-exercises/J-array-get-set/exercises2.js +++ b/week-2/1-exercises/J-array-get-set/exercises2.js @@ -6,8 +6,9 @@ - change the first value in the array to the number 1 */ -var numbers = [1, 2, 3]; // Don't change this array literal declaration - +var numbers = [ 1, 2, 3 ]; // Don't change this array literal declaration +numbers.push(4); +numbers[0] = 1; /* DO NOT EDIT BELOW THIS LINE --------------------------- */ From fd97683fa9b6b17eab0bc187061339c220878890 Mon Sep 17 00:00:00 2001 From: Abdennour Hachemi Date: Thu, 25 Jun 2020 19:12:44 +0100 Subject: [PATCH 38/65] solve fix-functions exercise --- week-2/2-mandatory/1-fix-functions.js | 104 ++++++++++++-------------- 1 file changed, 48 insertions(+), 56 deletions(-) diff --git a/week-2/2-mandatory/1-fix-functions.js b/week-2/2-mandatory/1-fix-functions.js index 6316fad..6461fc1 100644 --- a/week-2/2-mandatory/1-fix-functions.js +++ b/week-2/2-mandatory/1-fix-functions.js @@ -2,89 +2,81 @@ // Look at the tests and see how you can fix them. function mood() { - let isHappy = true; - - if (isHappy) { - return "I am happy"; - } else { - return "I am not happy"; - } + let isHappy = false; + + if (isHappy) { + console.log(' hppy is called'); + return 'I am happy'; + } else { + console.log(' not haapy is called'); + return 'I am not happy'; + } } function greaterThan10() { - let num = 10; - let isBigEnough; - - if (isBigEnough) { - return "num is greater than or equal to 10"; - } else { - return "num is not big enough"; - } + let num = 10; + let isBigEnough = num; + + if (isBigEnough >= num) { + return 'num is greater than or equal to 10'; + } else { + return 'num is not big enough'; + } } function sortArray() { - let letters = ["a", "n", "c", "e", "z", "f"]; - let sortedLetters; + let letters = [ 'a', 'n', 'c', 'e', 'z', 'f' ]; + let sortedLetters = letters.sort(); - return sortedLetters; + return sortedLetters; } function first5() { - let numbers = [1, 2, 3, 4, 5, 6, 7, 8]; - let sliced; + let numbers = [ 1, 2, 3, 4, 5, 6, 7, 8 ]; + let sliced = numbers.slice(0, 5); - return sliced; + return sliced; } function get3rdIndex(arr) { - let index = 3; - let element; + let index = 3; + let element = arr[index]; - return element; + return element; } /* ======= TESTS - DO NOT MODIFY ===== */ function test(test_name, expr) { - let status; - if (expr) { - status = "PASSED"; - } else { - status = "FAILED"; - } - - console.log(`${test_name}: ${status}`); + let status; + if (expr) { + status = 'PASSED'; + } else { + status = 'FAILED'; + } + + console.log(`${test_name}: ${status}`); } function arraysEqual(a, b) { - if (a === b) return true; - if (a == null || b == null) return false; - if (a.length != b.length) return false; + if (a === b) return true; + if (a == null || b == null) return false; + if (a.length != b.length) return false; - for (let i = 0; i < a.length; ++i) { - if (a[i] !== b[i]) return false; - } + for (let i = 0; i < a.length; ++i) { + if (a[i] !== b[i]) return false; + } - return true; + return true; } -test("mood function works", mood() === "I am not happy"); -test( - "greaterThanTen function works", - greaterThan10() === "num is greater than or equal to 10" -); -test( - "sortArray function works", - arraysEqual(sortArray(), ["a", "c", "e", "f", "n", "z"]) -); -test("first5 function works", arraysEqual(first5(), [1, 2, 3, 4, 5])); +test('mood function works', mood() === 'I am not happy'); +test('greaterThanTen function works', greaterThan10() === 'num is greater than or equal to 10'); +test('sortArray function works', arraysEqual(sortArray(), [ 'a', 'c', 'e', 'f', 'n', 'z' ])); +test('first5 function works', arraysEqual(first5(), [ 1, 2, 3, 4, 5 ])); test( - "get3rdIndex function works - case 1", - get3rdIndex(["fruit", "banana", "apple", "strawberry", "raspberry"]) === - "strawberry" -); -test( - "get3rdIndex function works - case 2", - get3rdIndex([11, 37, 62, 18, 19, 3, 30]) === 18 + 'get3rdIndex function works - case 1', + get3rdIndex([ 'fruit', 'banana', 'apple', 'strawberry', 'raspberry' ]) === 'strawberry' ); +test('get3rdIndex function works - case 2', get3rdIndex([ 11, 37, 62, 18, 19, 3, 30 ]) === 18); From 01a77657ac19d162914b4db1f827869ce4b82dd3 Mon Sep 17 00:00:00 2001 From: Abdennour Hachemi Date: Thu, 25 Jun 2020 19:14:23 +0100 Subject: [PATCH 39/65] solve function-creation exercise --- week-2/2-mandatory/2-function-creation.js | 136 +++++++++++++--------- 1 file changed, 79 insertions(+), 57 deletions(-) diff --git a/week-2/2-mandatory/2-function-creation.js b/week-2/2-mandatory/2-function-creation.js index bf7ecfd..914170c 100644 --- a/week-2/2-mandatory/2-function-creation.js +++ b/week-2/2-mandatory/2-function-creation.js @@ -5,7 +5,27 @@ Write a function that: - removes any forward slashes (/) in the strings - makes the string all lowercase */ -function tidyUpString(strArr) {} + +/* + var forwardSlachIndex = strArr[i].search('/'); + if (forwardSlachIndex >= 0) { + strArr[i] = + strArr[i].slice(0, forwardSlachIndex) + strArr[i].slice(forwardSlachIndex + 1, strArr[i].lenght); + } + +*/ +function tidyUpString(strArr) { + var forwardSlachIndex; + for (var i = 0; i < strArr.length; i++) { + strArr[i] = strArr[i].trim(); + forwardSlachIndex = strArr[i].search('/'); + if (forwardSlachIndex >= 0) { + strArr[i] = strArr[i].slice(forwardSlachIndex + 1, strArr[i].lenght); + } + strArr[i] = strArr[i].toLowerCase(); + } + return strArr; +} /* Complete the function to check if the variable `num` satisfies the following requirements: @@ -15,7 +35,13 @@ Complete the function to check if the variable `num` satisfies the following req Tip: use logical operators */ -function validate(num) {} +function validate(num) { + if (typeof num === 'number' && num % 2 === 0 && num <= 100) { + return true; + } else { + return false; + } +} /* Write a function that removes an element from an array @@ -26,7 +52,7 @@ The function must: */ function remove(arr, index) { - return; // complete this statement + return arr.slice(0, index).concat(arr.slice(index + 1, arr.length)); // complete this statement } /* @@ -38,79 +64,75 @@ Write a function that: */ function formatPercentage(arr) { - + for (var i = 0; i < arr.length; i++) { + if (arr[i] > 100) { + arr[i] = 100; + } else { + arr[i] = Math.round(arr[i] * 100) / 100; + } + arr[i] += '%'; + } + return arr; } +console.log(formatPercentage([ 23, 18, 187.2, 0.372 ])); /* ======= TESTS - DO NOT MODIFY ===== */ function arraysEqual(a, b) { - if (a === b) return true; - if (a == null || b == null) return false; - if (a.length != b.length) return false; + if (a === b) return true; + if (a == null || b == null) return false; + if (a.length != b.length) return false; - for (let i = 0; i < a.length; ++i) { - if (a[i] !== b[i]) return false; - } + for (let i = 0; i < a.length; ++i) { + if (a[i] !== b[i]) return false; + } - return true; + return true; } function test(test_name, expr) { - let status; - if (expr) { - status = "PASSED"; - } else { - status = "FAILED"; - } - - console.log(`${test_name}: ${status}`); + let status; + if (expr) { + status = 'PASSED'; + } else { + status = 'FAILED'; + } + + console.log(`${test_name}: ${status}`); } test( - "tidyUpString function works - case 1", - arraysEqual(tidyUpString(["/Daniel ", "irina ", " Gordon", "ashleigh "]), [ - "daniel", - "irina", - "gordon", - "ashleigh" - ]) + 'tidyUpString function works - case 1', + arraysEqual(tidyUpString([ '/Daniel ', 'irina ', ' Gordon', 'ashleigh ' ]), [ + 'daniel', + 'irina', + 'gordon', + 'ashleigh' + ]) ); test( - "tidyUpString function works - case 2", - arraysEqual( - tidyUpString([" /Sanyia ", " Michael ", "AnTHonY ", " Tim "]), - ["sanyia", "michael", "anthony", "tim"] - ) + 'tidyUpString function works - case 2', + arraysEqual(tidyUpString([ ' /Sanyia ', ' Michael ', 'AnTHonY ', ' Tim ' ]), [ + 'sanyia', + 'michael', + 'anthony', + 'tim' + ]) ); -test("validate function works - case 1", validate(10) === true); -test("validate function works - case 2", validate(18) === true); -test("validate function works - case 3", validate(17) === false); -test("validate function works - case 4", validate("Ten") === false); -test("validate function works - case 5", validate(108) === false); +test('validate function works - case 1', validate(10) === true); +test('validate function works - case 2', validate(18) === true); +test('validate function works - case 3', validate(17) === false); +test('validate function works - case 4', validate('Ten') === false); +test('validate function works - case 5', validate(108) === false); +test('remove function works - case 1', arraysEqual(remove([ 10, 293, 292, 176, 29 ], 3), [ 10, 293, 292, 29 ])); test( - "remove function works - case 1", - arraysEqual(remove([10, 293, 292, 176, 29], 3), [10, 293, 292, 29]) -); -test( - "remove function works - case 1", - arraysEqual(remove(["a", "b", "c", "d", "e", "f", "g"], 6), [ - "a", - "b", - "c", - "d", - "e", - "f" - ]) + 'remove function works - case 1', + arraysEqual(remove([ 'a', 'b', 'c', 'd', 'e', 'f', 'g' ], 6), [ 'a', 'b', 'c', 'd', 'e', 'f' ]) ); test( - "formatPercentage function works - case 1", - arraysEqual(formatPercentage([23, 18, 187.2, 0.372]), [ - "23%", - "18%", - "100%", - "0.37%" - ]) -); \ No newline at end of file + 'formatPercentage function works - case 1', + arraysEqual(formatPercentage([ 23, 18, 187.2, 0.372 ]), [ '23%', '18%', '100%', '0.37%' ]) +); From 9e9acbfa04912f6510991d53ab0da4acdc5bf4c8 Mon Sep 17 00:00:00 2001 From: Abdennour Hachemi Date: Thu, 25 Jun 2020 19:16:24 +0100 Subject: [PATCH 40/65] solve plying-computer exercise --- week-2/2-mandatory/3-playing-computer.js | 33 ++++++++++++++++-------- 1 file changed, 22 insertions(+), 11 deletions(-) diff --git a/week-2/2-mandatory/3-playing-computer.js b/week-2/2-mandatory/3-playing-computer.js index 0fa7c04..810091d 100644 --- a/week-2/2-mandatory/3-playing-computer.js +++ b/week-2/2-mandatory/3-playing-computer.js @@ -15,28 +15,39 @@ 7. What is the value of the "a" outer variable when "f1" is called for the first time? */ +//Answers: +// 1. Varible b is not defined which cause an error to be thrown. +// 2. Line 40 has been removed. +// 3. The console will print 2 6 4 9 6 13 8. +// 4. f1 will be executed 2 times, when the loop counter i has odd value of 1 and 3. +// 5. f2 will be executed 3 times when the loop counter i has even value of 0,2 and 4. +// 6. The "a" parameter take in the first "f1" call the value of i which is 1. +// 7. The value "a" outer variable when "f1" is called for the first time is 8 ? + let x = 2; let a = 6; const f1 = function(a, b) { - return a + b; + return a + b; }; + const f2 = function(a, b) { - return a + b + x; + return a + b + x; }; console.log(x); console.log(a); -console.log(b); +//console.log(b); for (let i = 0; i < 5; ++i) { - a = a + 1; - if (i % 2 === 0) { - const d = f2(i, x); - console.log(d); - } else { - const e = f1(i, a); - console.log(e); - } + a = a + 1; + if (i % 2 === 0) { + // if i is an even number call f2:it will be executed when i =0,2,4 . + const d = f2(i, x); + console.log(d); + } else { + const e = f1(i, a); // if i is an odd number call f1: it will be executed when i =1,3 . + console.log(e); + } } From 72f97b04ec20cd9b3b2a080b65740d2a0066a6cc Mon Sep 17 00:00:00 2001 From: Abdennour Hachemi Date: Thu, 25 Jun 2020 19:18:16 +0100 Subject: [PATCH 41/65] solving sorting-algorithm exercise --- week-2/2-mandatory/4-sorting-algorithm.js | 81 ++++++++++++----------- 1 file changed, 41 insertions(+), 40 deletions(-) diff --git a/week-2/2-mandatory/4-sorting-algorithm.js b/week-2/2-mandatory/4-sorting-algorithm.js index 3603942..2dfd8c8 100644 --- a/week-2/2-mandatory/4-sorting-algorithm.js +++ b/week-2/2-mandatory/4-sorting-algorithm.js @@ -14,57 +14,58 @@ You don't have to worry about making this algorithm work fast! The idea is to ge "think" like a computer and practice your knowledge of basic JavaScript. */ -function sortAges(arr) {} +function sortAges(arr) { + + var ArrayOfNumbers = []; + for (var i = 0; i < arr.length; i++) { + if (typeof arr[i] === 'number') { + ArrayOfNumbers.push(arr[i]); + } + } + + arr = ArrayOfNumbers; + var temp; + for (var k = 0; k < arr.length; k++) { + for (var j = k + 1; j < arr.length; j++) { + if (arr[k] > arr[j]) { + temp = arr[k]; + arr[k] = arr[j]; + arr[j] = temp; + } + } + } + + return arr; +} /* ======= TESTS - DO NOT MODIFY ===== */ -const agesCase1 = [ - "🎹", - 100, - "💩", - 55, - "🥵", - "🙈", - 45, - "🍕", - "Sanyia", - 66, - "James", - 23, - "🎖", - "Ismeal", -]; -const agesCase2 = ["28", 100, 60, 55, "75", "🍕", "Elamin"]; +const agesCase1 = [ '🎹', 100, '💩', 55, '🥵', '🙈', 45, '🍕', 'Sanyia', 66, 'James', 23, '🎖', 'Ismeal' ]; +const agesCase2 = [ '28', 100, 60, 55, '75', '🍕', 'Elamin' ]; function arraysEqual(a, b) { - if (a === b) return true; - if (a == null || b == null) return false; - if (a.length != b.length) return false; + if (a === b) return true; + if (a == null || b == null) return false; + if (a.length != b.length) return false; - for (let i = 0; i < a.length; ++i) { - if (a[i] !== b[i]) return false; - } + for (let i = 0; i < a.length; ++i) { + if (a[i] !== b[i]) return false; + } - return true; + return true; } function test(test_name, expr) { - let status; - if (expr) { - status = "PASSED"; - } else { - status = "FAILED"; - } + let status; + if (expr) { + status = 'PASSED'; + } else { + status = 'FAILED'; + } - console.log(`${test_name}: ${status}`); + console.log(`${test_name}: ${status}`); } -test( - "sortAges function works - case 1", - arraysEqual(sortAges(agesCase1), [23, 45, 55, 66, 100]) -); +test('sortAges function works - case 1', arraysEqual(sortAges(agesCase1), [ 23, 45, 55, 66, 100 ])); -test( - "sortAges function works - case 2", - arraysEqual(sortAges(agesCase2), [55, 60, 100]) -); +test('sortAges function works - case 2', arraysEqual(sortAges(agesCase2), [ 55, 60, 100 ])); From 07880c1392d3ae97fa0fec7c3031d233cf8c871a Mon Sep 17 00:00:00 2001 From: Abdennour Hachemi Date: Thu, 25 Jun 2020 19:23:21 +0100 Subject: [PATCH 42/65] solving first question of radio-stations exercise --- week-2/3-extra/1-radio-stations.js | 180 ++++++++++++++++++++--------- 1 file changed, 126 insertions(+), 54 deletions(-) diff --git a/week-2/3-extra/1-radio-stations.js b/week-2/3-extra/1-radio-stations.js index 95c0e56..124aa2d 100644 --- a/week-2/3-extra/1-radio-stations.js +++ b/week-2/3-extra/1-radio-stations.js @@ -25,74 +25,146 @@ * - Return only the frequencies that are radio stations. */ // `getStations` goes here +/* +function getStations() { + var af = getAllFrequencies(); + var currentStation = Math.floor(Math.random() * (108 - 87 + 1) + 87); + console.log(currentStation); + isRadioFrequency(currentStation); + return currentStation; +} +function isRadioFrequency(frequency) { + found = false; + var af = getAllFrequencies(); + for (var i = 0; i < af.length; i++) { + if (af[i] === frequency) { + found = true; + } + } + + return found; +} +*/ +//---------------------------------------------------------------------- +/** + * Finding a radio station, and a good one, can be hard manually. + * Let's use some code to help us build a program that helps us scan + * the radio waves for some good music. + */ + +/** + * First, let's create a function that creates a list of all the frequencies. + * Call this function `getAllFrequencies`. + * + * This function should: + * - Create an array starting at 87 and ending in 108 + * - Should return this array to use in other functions + */ + +// `getAllFrequencies` goes here +function getAllFrequencies() { + frequenciesArray = []; + for (var i = 0; i <= 108 - 87; i++) { + frequenciesArray[i] = 87 + i; + } + return frequenciesArray; +} + +/** + * Next, let's write a function that gives us only the frequencies that are radio stations. + * Call this function `getStations`. + * + * This function should: + * - Get the available frequencies from `getAllFrequencies` + * - There is a helper function called isRadioFrequency that takes an integer as an argument and returns a boolean. + * - Return only the frequencies that are radio stations. + */ +// `getStations` goes here +function getStations() { + var af = getAllFrequencies(); + + var currentStation = Math.floor(Math.random() * (108 - 87 + 1) + 87); + + isRadioFrequency(currentStation); + return currentStation; +} +function isRadioFrequency(frequency) { + found = false; + var af = getAllFrequencies(); + for (var i = 0; i < af.length; i++) { + if (af[i] === frequency) { + found = true; + } + } + + return found; +} /* ======= TESTS - DO NOT MODIFY ======= */ function getAvailableStations() { - // Using `stations` as a property as defining it as a global variable wouldn't - // always make it initialized before the function is called - if (!getAvailableStations.stations) { - const stationCount = 4; - getAvailableStations.stations = new Array(stationCount) - .fill(undefined) - .map(function() { - return Math.floor(Math.random() * (108 - 87 + 1) + 87); - }) - .sort(function(frequencyA, frequencyB) { - return frequencyA - frequencyB; - }); - } - - return getAvailableStations.stations; + // Using `stations` as a property as defining it as a global variable wouldn't + // always make it initialized before the function is called + if (!getAvailableStations.stations) { + const stationCount = 4; + getAvailableStations.stations = new Array(stationCount) + .fill(undefined) + .map(function() { + return Math.floor(Math.random() * (108 - 87 + 1) + 87); + }) + .sort(function(frequencyA, frequencyB) { + return frequencyA - frequencyB; + }); + } + + return getAvailableStations.stations; } function isRadioStation(frequency) { - return getAvailableStations().includes(frequency); + return getAvailableStations().includes(frequency); } -const assert = require("assert"); +const assert = require('assert'); function test(testName, fn) { - try { - fn(); - console.log(`\n✅ ${testName}: PASS`); - } catch (error) { - console.log( - `\n❌ ${testName}: FAIL (see details below)\n\n${error.message}` - ); - } + try { + fn(); + console.log(`\n✅ ${testName}: PASS`); + } catch (error) { + console.log(`\n❌ ${testName}: FAIL (see details below)\n\n${error.message}`); + } } -test("getAllFrequencies() returns all frequencies between 87 and 108", function() { - const frequencies = getAllFrequencies(); - assert.deepStrictEqual(frequencies, [ - 87, - 88, - 89, - 90, - 91, - 92, - 93, - 94, - 95, - 96, - 97, - 98, - 99, - 100, - 101, - 102, - 103, - 104, - 105, - 106, - 107, - 108 - ]); +test('getAllFrequencies() returns all frequencies between 87 and 108', function() { + const frequencies = getAllFrequencies(); + assert.deepStrictEqual(frequencies, [ + 87, + 88, + 89, + 90, + 91, + 92, + 93, + 94, + 95, + 96, + 97, + 98, + 99, + 100, + 101, + 102, + 103, + 104, + 105, + 106, + 107, + 108 + ]); }); -test("getStations() returns all the available stations", () => { - const stations = getStations(); - assert.deepStrictEqual(stations, getAvailableStations()); +test('getStations() returns all the available stations', () => { + const stations = getStations(); + assert.deepStrictEqual(stations, getAvailableStations()); }); From b94d3c56e3e8b9137a3e7c5d606f47b11c27cec4 Mon Sep 17 00:00:00 2001 From: Abdennour Hachemi Date: Fri, 26 Jun 2020 01:22:58 +0100 Subject: [PATCH 43/65] updating week number --- .github/pull_request_template.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/pull_request_template.md b/.github/pull_request_template.md index 8c3a067..c1fe243 100644 --- a/.github/pull_request_template.md +++ b/.github/pull_request_template.md @@ -7,4 +7,4 @@ Your Slack Name:nouri89 # Homework Details Module:javaScript -Week:1 +Week:2 From 1cf6135a38e7d3773070c474d4dd965c336579c8 Mon Sep 17 00:00:00 2001 From: Abdennour Hachemi Date: Fri, 26 Jun 2020 02:37:05 +0100 Subject: [PATCH 44/65] Solving radio stations exercise --- week-2/3-extra/1-radio-stations.js | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/week-2/3-extra/1-radio-stations.js b/week-2/3-extra/1-radio-stations.js index 124aa2d..efef574 100644 --- a/week-2/3-extra/1-radio-stations.js +++ b/week-2/3-extra/1-radio-stations.js @@ -82,13 +82,16 @@ function getAllFrequencies() { */ // `getStations` goes here function getStations() { - var af = getAllFrequencies(); - - var currentStation = Math.floor(Math.random() * (108 - 87 + 1) + 87); - - isRadioFrequency(currentStation); - return currentStation; + let radioStations = getAllFrequencies(); + let validStations = []; + for (let i = 0; i < radioStations.length; i++) { + if (isRadioStation(radioStations[i])) { + validStations.push(radioStations[i]); + } + } + return validStations; } + function isRadioFrequency(frequency) { found = false; var af = getAllFrequencies(); From ad6acba4367d0dcca7dbda8f6a7cb3c108718c24 Mon Sep 17 00:00:00 2001 From: Abdennour Hachemi Date: Sat, 4 Jul 2020 00:44:06 +0100 Subject: [PATCH 45/65] solved --- week-3/1-exercises/A-array-find/exercise.js | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/week-3/1-exercises/A-array-find/exercise.js b/week-3/1-exercises/A-array-find/exercise.js index d7fd51f..760f38f 100644 --- a/week-3/1-exercises/A-array-find/exercise.js +++ b/week-3/1-exercises/A-array-find/exercise.js @@ -4,12 +4,15 @@ */ // write your code here +function isLongerNameAndStartWithA(names) { + return names.charAt(0) === 'A' && names.length > 7; +} -var names = ["Rakesh", "Antonio", "Alexandra", "Andronicus", "Annam", "Mikey", "Anastasia", "Karim", "Ahmed"]; - -var longNameThatStartsWithA = findLongNameThatStartsWithA(names); - -console.log(longNameThatStartsWithA); +var names = [ 'Rakesh', 'Antonio', 'Alexandra', 'Andronicus', 'Annam', 'Mikey', 'Anastasia', 'Karim', 'Ahmed' ]; +//names.find(isLongerNameAndStartWithA(names)); +//var longNameThatStartsWithA = findLongNameThatStartsWithA(names); +var nameFound = names.find(isLongerNameAndStartWithA); +console.log(nameFound); /* EXPECTED OUTPUT */ // "Alexandra" From b1bbb6a64da3ce92e177b33a9a731606ee151790 Mon Sep 17 00:00:00 2001 From: Abdennour Hachemi Date: Sat, 4 Jul 2020 00:46:03 +0100 Subject: [PATCH 46/65] solved --- week-3/1-exercises/B-array-some/exercise.js | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/week-3/1-exercises/B-array-some/exercise.js b/week-3/1-exercises/B-array-some/exercise.js index 965c052..698de86 100644 --- a/week-3/1-exercises/B-array-some/exercise.js +++ b/week-3/1-exercises/B-array-some/exercise.js @@ -5,20 +5,26 @@ - Add a check for null values, and if one exists, exit the program - Do not edit any of the existing code */ - -var pairsByIndex = [[0, 3], [1, 2], [2, 1], null, [3, 0]]; + +var pairsByIndex = [ [ 0, 3 ], [ 1, 2 ], [ 2, 1 ], null, [ 3, 0 ] ]; // If there is a null value in the array exit the program with the error code // https://nodejs.org/api/process.html#process_process_exit_code // process.exit(1); -var students = ["Islam", "Lesley", "Harun", "Rukmini"]; -var mentors = ["Daniel", "Irina", "Mozafar", "Luke"]; +var students = [ 'Islam', 'Lesley', 'Harun', 'Rukmini' ]; +var mentors = [ 'Daniel', 'Irina', 'Mozafar', 'Luke' ]; var pairs = pairsByIndex.map(function(indexes) { - var student = students[indexes[0]]; - var mentor = mentors[indexes[1]]; - return [student, mentor]; + if (indexes === null) { + console.log('Error: A null value found'); + process.exit(1); + + } + var student = students[indexes[0]]; + var mentor = mentors[indexes[1]]; + return [ student, mentor ]; }); console.log(pairs); + From c952303f3ea12d4d61511f0a99e75546dfa5d22d Mon Sep 17 00:00:00 2001 From: Abdennour Hachemi Date: Sat, 4 Jul 2020 00:49:00 +0100 Subject: [PATCH 47/65] solved --- week-3/1-exercises/C-array-every/exercise.js | 30 +++++++++++++------- 1 file changed, 19 insertions(+), 11 deletions(-) diff --git a/week-3/1-exercises/C-array-every/exercise.js b/week-3/1-exercises/C-array-every/exercise.js index b515e94..6c7157c 100644 --- a/week-3/1-exercises/C-array-every/exercise.js +++ b/week-3/1-exercises/C-array-every/exercise.js @@ -1,18 +1,26 @@ /* - This program should check if the array `group` contains only students + You are given a program that logs pairings between mentors and students + It fails because the array `pairsById` can contain different values that break the program + It is decided that array items which are not pairs should be filtered out + - Finish the statement on line 11 to produce an array with valid content + - Do not edit any of the existing code */ -var students = ["Omar", "Austine", "Dany", "Swathi", "Lesley", "Rukmini"]; -var group = ["Austine", "Dany", "Swathi", "Daniel"]; +var pairsByIndexRaw = [ [ 0, 3 ], [ 1, 2 ], [ 2, 1 ], null, [ 1 ], false, 'whoops' ]; -var groupIsOnlyStudents; // complete this statement +var pairsByIndex = pairsByIndexRaw.filter(function(pair) { + return Array.isArray(pair) && pair.length === 2; +}); -if (groupIsOnlyStudents) { - console.log("The group contains only students"); -} else { - console.log("The group does not contain only students"); -} +// Complete this statement -/* EXPECTED RESULT */ +var students = [ 'Islam', 'Lesley', 'Harun', 'Rukmini' ]; +var mentors = [ 'Daniel', 'Irina', 'Mozafar', 'Luke' ]; -// The group does not contain only students +var pairs = pairsByIndex.map(function(indexes) { + var student = students[indexes[0]]; + var mentor = mentors[indexes[1]]; + return [ student, mentor ]; +}); + +console.log(pairs); From a4e3f82212a46ff8f315569d116d10cd51557125 Mon Sep 17 00:00:00 2001 From: Abdennour Hachemi Date: Mon, 6 Jul 2020 00:11:13 +0100 Subject: [PATCH 48/65] Update week number --- .github/pull_request_template.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/pull_request_template.md b/.github/pull_request_template.md index c1fe243..f907535 100644 --- a/.github/pull_request_template.md +++ b/.github/pull_request_template.md @@ -7,4 +7,4 @@ Your Slack Name:nouri89 # Homework Details Module:javaScript -Week:2 +Week:3 From cb14d9e01c73c52de9b75bf0815908d884748c94 Mon Sep 17 00:00:00 2001 From: Abdennour Hachemi Date: Mon, 6 Jul 2020 00:14:20 +0100 Subject: [PATCH 49/65] solved --- week-3/1-exercises/D-array-filter/exercise.js | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/week-3/1-exercises/D-array-filter/exercise.js b/week-3/1-exercises/D-array-filter/exercise.js index 6e32cc6..6c7157c 100644 --- a/week-3/1-exercises/D-array-filter/exercise.js +++ b/week-3/1-exercises/D-array-filter/exercise.js @@ -6,17 +6,21 @@ - Do not edit any of the existing code */ -var pairsByIndexRaw = [[0, 3], [1, 2], [2, 1], null, [1], false, "whoops"]; +var pairsByIndexRaw = [ [ 0, 3 ], [ 1, 2 ], [ 2, 1 ], null, [ 1 ], false, 'whoops' ]; -var pairsByIndex; // Complete this statement +var pairsByIndex = pairsByIndexRaw.filter(function(pair) { + return Array.isArray(pair) && pair.length === 2; +}); + +// Complete this statement -var students = ["Islam", "Lesley", "Harun", "Rukmini"]; -var mentors = ["Daniel", "Irina", "Mozafar", "Luke"]; +var students = [ 'Islam', 'Lesley', 'Harun', 'Rukmini' ]; +var mentors = [ 'Daniel', 'Irina', 'Mozafar', 'Luke' ]; var pairs = pairsByIndex.map(function(indexes) { - var student = students[indexes[0]]; - var mentor = mentors[indexes[1]]; - return [student, mentor]; + var student = students[indexes[0]]; + var mentor = mentors[indexes[1]]; + return [ student, mentor ]; }); console.log(pairs); From ba940e21eeec497524498b6ac891df50b0560bc3 Mon Sep 17 00:00:00 2001 From: Abdennour Hachemi Date: Mon, 6 Jul 2020 00:15:45 +0100 Subject: [PATCH 50/65] solved --- week-3/1-exercises/E-array-map/exercise.js | 25 +++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/week-3/1-exercises/E-array-map/exercise.js b/week-3/1-exercises/E-array-map/exercise.js index 2835e92..bb7804d 100644 --- a/week-3/1-exercises/E-array-map/exercise.js +++ b/week-3/1-exercises/E-array-map/exercise.js @@ -1,5 +1,28 @@ // Using the .map() method, create a new array with `numbers` multiplied by 100 // Write multiple solutions using different syntax (as shown in the README) -var numbers = [0.1, 0.2, 0.3, 0.4, 0.5]; +var numbers = [ 0.1, 0.2, 0.3, 0.4, 0.5 ]; +var numbersX100 = numbers.map(multiplyByCent); +function multiplyByCent(number) { + return number * 100; +} +console.log(numbersX100 + ' First way'); +var numbersX100nd = numbers.map(function multiplyByCent(number) { + return number * 100; +}); +console.log(numbersX100nd + ' secound way'); + +var numbersX100rd = numbers.map(number => number * 100); + +console.log(numbersX100rd + ' third way'); + +var numbersX100th = numbers.map(number => { + return number * 100; +}); +console.log(numbersX100th + ' fourth way'); + +var numberX100last = numbers.map(function(number) { + return number * 100; +}); +console.log(numberX100last + ' fifth way'); From b90c06f1466a64521c89aa2c015c08807a8f59a1 Mon Sep 17 00:00:00 2001 From: Abdennour Hachemi Date: Mon, 6 Jul 2020 00:26:13 +0100 Subject: [PATCH 51/65] solved --- week-3/1-exercises/F-array-forEach/exercise.js | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/week-3/1-exercises/F-array-forEach/exercise.js b/week-3/1-exercises/F-array-forEach/exercise.js index e83e2df..92280d7 100644 --- a/week-3/1-exercises/F-array-forEach/exercise.js +++ b/week-3/1-exercises/F-array-forEach/exercise.js @@ -7,7 +7,16 @@ An array with numbers 1-15 has been provided. */ -var arr = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15]; +var arr = [ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15 ]; + +var alteredArray = arr.forEach(function(name) { + if (name % 3 === 0 && name % 5 === 0) console.log('FizzBuzz'); + else if (name % 3 === 0) console.log('Fizz'); + else if (name % 5 === 0) console.log('Buzz'); + else console.log(name); +}); + +console.log(alteredArray); /* EXPECTED OUTPUT */ From be658f7c753b814c0639abc539b3666df75d4b4b Mon Sep 17 00:00:00 2001 From: Abdennour Hachemi Date: Mon, 6 Jul 2020 00:27:37 +0100 Subject: [PATCH 52/65] solved --- week-3/1-exercises/G-array-methods/exercise.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/week-3/1-exercises/G-array-methods/exercise.js b/week-3/1-exercises/G-array-methods/exercise.js index 44e9c80..5dc3c88 100644 --- a/week-3/1-exercises/G-array-methods/exercise.js +++ b/week-3/1-exercises/G-array-methods/exercise.js @@ -4,7 +4,7 @@ */ var numbers = [3, 2, 1]; -var sortedNumbers; // complete this statement +var sortedNumbers=numbers.sort(); // complete this statement /* DO NOT EDIT BELOW THIS LINE From 3b5b4e4f3522e47ec7ffaf72af1a619246c4c17b Mon Sep 17 00:00:00 2001 From: Abdennour Hachemi Date: Mon, 6 Jul 2020 00:28:50 +0100 Subject: [PATCH 53/65] solved --- week-3/1-exercises/G-array-methods/exercise2.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/week-3/1-exercises/G-array-methods/exercise2.js b/week-3/1-exercises/G-array-methods/exercise2.js index 3dd24a1..461b0d7 100644 --- a/week-3/1-exercises/G-array-methods/exercise2.js +++ b/week-3/1-exercises/G-array-methods/exercise2.js @@ -4,10 +4,10 @@ The variable everyone should be an array containing both mentors and students. */ -var mentors = ["Daniel", "Irina", "Rares"]; -var students = ["Rukmini", "Abdul", "Austine", "Swathi"]; +var mentors = [ 'Daniel', 'Irina', 'Rares' ]; +var students = [ 'Rukmini', 'Abdul', 'Austine', 'Swathi' ]; -var everyone; // complete this statement +var everyone = mentors.concat(students); // complete this statement /* DO NOT EDIT BELOW THIS LINE From 8c59b196fcea821ed1665ab0e4628d49f6d152cb Mon Sep 17 00:00:00 2001 From: Abdennour Hachemi Date: Mon, 6 Jul 2020 00:46:40 +0100 Subject: [PATCH 54/65] solved --- week-3/1-exercises/H-array-methods-2/exercise.js | 14 +++----------- 1 file changed, 3 insertions(+), 11 deletions(-) diff --git a/week-3/1-exercises/H-array-methods-2/exercise.js b/week-3/1-exercises/H-array-methods-2/exercise.js index d36303b..73b9a49 100644 --- a/week-3/1-exercises/H-array-methods-2/exercise.js +++ b/week-3/1-exercises/H-array-methods-2/exercise.js @@ -5,18 +5,10 @@ The variable `lastFive` should contain the last five items of `everyone` */ -var everyone = [ - "Daniel", - "Irina", - "Rares", - "Rukmini", - "Abdul", - "Austine", - "Swathi" -]; +var everyone = [ 'Daniel', 'Irina', 'Rares', 'Rukmini', 'Abdul', 'Austine', 'Swathi' ]; -var firstFive; // complete this statement -var lastFive; // complete this statement +var firstFive = everyone.slice(0, 5); // complete this statement +var lastFive = everyone.slice(everyone.length - 5, everyone.length); // complete this statement /* DO NOT EDIT BELOW THIS LINE From 26c9b87cdb15fedc709d6ca0ccdbd930e1f435d9 Mon Sep 17 00:00:00 2001 From: Abdennour Hachemi Date: Mon, 6 Jul 2020 00:48:25 +0100 Subject: [PATCH 55/65] solved --- week-3/1-exercises/H-array-methods-2/exercise2.js | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/week-3/1-exercises/H-array-methods-2/exercise2.js b/week-3/1-exercises/H-array-methods-2/exercise2.js index b7be576..72be0fb 100644 --- a/week-3/1-exercises/H-array-methods-2/exercise2.js +++ b/week-3/1-exercises/H-array-methods-2/exercise2.js @@ -7,15 +7,21 @@ Tip: use the string method .split() and the array method .join() */ -function capitalise(str) {} +function capitalise(str) { + let stringToarray = str.split(''); + stringToarray[0] = stringToarray[0].toUpperCase(); + let orginalString = stringToarray.join(''); + + return orginalString; +} /* DO NOT EDIT BELOW THIS LINE --------------------------- */ -var name = "daniel"; +var name = 'daniel'; console.log(capitalise(name)); -console.log(capitalise("hello")); +console.log(capitalise('hello')); /* EXPECTED RESULT From 7e426be4934fc6ea1cc0ad3ef9fb346513ac760b Mon Sep 17 00:00:00 2001 From: Abdennour Hachemi Date: Mon, 6 Jul 2020 00:49:47 +0100 Subject: [PATCH 56/65] solved --- week-3/1-exercises/H-array-methods-2/exercise3.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/week-3/1-exercises/H-array-methods-2/exercise3.js b/week-3/1-exercises/H-array-methods-2/exercise3.js index 82e9dd8..8074da4 100644 --- a/week-3/1-exercises/H-array-methods-2/exercise3.js +++ b/week-3/1-exercises/H-array-methods-2/exercise3.js @@ -7,7 +7,8 @@ var ukNations = ["Scotland", "Wales", "England", "Northern Ireland"]; function isInUK(country) { - return; // complete this statement + return ukNations.includes(country); + ; // complete this statement } /* From 3b5579cb9967c2613fe051cba58f9447401fd169 Mon Sep 17 00:00:00 2001 From: Abdennour Hachemi Date: Mon, 6 Jul 2020 00:55:18 +0100 Subject: [PATCH 57/65] solved --- week-3/2-mandatory/1-oxygen-levels.js | 39 +++++++++++++-------------- 1 file changed, 19 insertions(+), 20 deletions(-) diff --git a/week-3/2-mandatory/1-oxygen-levels.js b/week-3/2-mandatory/1-oxygen-levels.js index 3c02135..5975e29 100644 --- a/week-3/2-mandatory/1-oxygen-levels.js +++ b/week-3/2-mandatory/1-oxygen-levels.js @@ -9,32 +9,31 @@ To be safe, they need to land on the first unamed planet that has Oxygen levels Write a function that finds the oxygen level of the first safe planet - Oxygen between 19.5% and 23.5% */ -function safeLevels() { - +function safeLevels(arr) { + let test = arr.sort(); + var level1 = test.find(function(level) { + return parseFloat(level) > 19.5; + }); + return level1; + } /* ======= TESTS - DO NOT MODIFY ===== */ -const oxygenLevels1 = ["24.2%", "11.3%", "19.9%", "23.1%", "29.3%", "20.2%"] -const oxygenLevels2 = ["30.8%", "23.5%", "18.8%", "19.5%", "20.2%", "31.6%"] +const oxygenLevels1 = [ '24.2%', '11.3%', '19.9%', '23.1%', '29.3%', '20.2%' ]; +const oxygenLevels2 = [ '30.8%', '23.5%', '18.8%', '19.5%', '20.2%', '31.6%' ]; function test(test_name, expr) { - let status; - if (expr) { - status = "PASSED"; - } else { - status = "FAILED"; - } - - console.log(`${test_name}: ${status}`); + let status; + if (expr) { + status = 'PASSED'; + } else { + status = 'FAILED'; + } + + console.log(`${test_name}: ${status}`); } -test( - "safeLevels function works - case 2", - safeLevels(oxygenLevels1) === "19.9%" -); +test('safeLevels function works - case 2', safeLevels(oxygenLevels1) === '19.9%'); -test( - "safeLevels function works - case 2", - safeLevels(oxygenLevels2) === "20.2%" -); \ No newline at end of file +test('safeLevels function works - case 2', safeLevels(oxygenLevels2) === '20.2%'); From 71051f58a194b3caf1a44d1912ea8ed543fed95c Mon Sep 17 00:00:00 2001 From: Abdennour Hachemi Date: Mon, 6 Jul 2020 00:57:36 +0100 Subject: [PATCH 58/65] solved --- week-3/2-mandatory/2-bush-berries.js | 36 +++++++++++++++++----------- 1 file changed, 22 insertions(+), 14 deletions(-) diff --git a/week-3/2-mandatory/2-bush-berries.js b/week-3/2-mandatory/2-bush-berries.js index d900323..9374170 100644 --- a/week-3/2-mandatory/2-bush-berries.js +++ b/week-3/2-mandatory/2-bush-berries.js @@ -10,25 +10,33 @@ Use the tests to confirm which message to return */ -function bushChecker() { - +function bushChecker(arr) { + var test1 = arr.every(function(item) { + return item === 'pink'; + }); + + if (test1 === true) { + return 'Bush is safe to eat from'; + } else { + return 'Toxic! Leave bush alone!'; + } } /* ======= TESTS - DO NOT MODIFY ===== */ -let bushBerryColours1 = ["pink", "pink", "pink", "neon", "pink", "transparent"] -let bushBerryColours2 = ["pink", "pink", "pink", "pink"] +let bushBerryColours1 = [ 'pink', 'pink', 'pink', 'neon', 'pink', 'transparent' ]; +let bushBerryColours2 = [ 'pink', 'pink', 'pink', 'pink' ]; function test(test_name, expr) { - let status; - if (expr) { - status = "PASSED"; - } else { - status = "FAILED"; - } - - console.log(`${test_name}: ${status}`); + let status; + if (expr) { + status = 'PASSED'; + } else { + status = 'FAILED'; + } + + console.log(`${test_name}: ${status}`); } -test("bushChecker funtion works - case 1", bushChecker(bushBerryColours1) === "Toxic! Leave bush alone!") -test("bushChecker funtion works - case 1", bushChecker(bushBerryColours2) === "Bush is safe to eat from") +test('bushChecker funtion works - case 1', bushChecker(bushBerryColours1) === 'Toxic! Leave bush alone!'); +test('bushChecker funtion works - case 1', bushChecker(bushBerryColours2) === 'Bush is safe to eat from'); From 5ac4e9de7df1f93e5a6605006aade73f4f41621c Mon Sep 17 00:00:00 2001 From: Abdennour Hachemi Date: Mon, 6 Jul 2020 00:58:30 +0100 Subject: [PATCH 59/65] Update 3-space-colonies.js --- week-3/2-mandatory/3-space-colonies.js | 67 ++++++++++++++------------ 1 file changed, 35 insertions(+), 32 deletions(-) diff --git a/week-3/2-mandatory/3-space-colonies.js b/week-3/2-mandatory/3-space-colonies.js index f99891a..7de5dee 100644 --- a/week-3/2-mandatory/3-space-colonies.js +++ b/week-3/2-mandatory/3-space-colonies.js @@ -8,50 +8,53 @@ NOTE: don't include any element that is not a "family". */ -function colonisers() { - +function colonisers(arr) { + return arr.filter(function(members) { + return members[0] === 'A' && members.includes('family'); + }); } /* ======= TESTS - DO NOT MODIFY ===== */ const voyagers = [ - "Adam family", - "Potter family", - "Eric", - "Aldous", - "Button family", - "Jude", - "Carmichael", - "Bunny", - "Asimov", - "Oscar family", - "Avery family", - "Archer family" + 'Adam family', + 'Potter family', + 'Eric', + 'Aldous', + 'Button family', + 'Jude', + 'Carmichael', + 'Bunny', + 'Asimov', + 'Oscar family', + 'Avery family', + 'Archer family' ]; function arraysEqual(a, b) { - if (a === b) return true; - if (a == null || b == null) return false; - if (a.length != b.length) return false; + if (a === b) return true; + if (a == null || b == null) return false; + if (a.length != b.length) return false; - for (let i = 0; i < a.length; ++i) { - if (a[i] !== b[i]) return false; - } + for (let i = 0; i < a.length; ++i) { + if (a[i] !== b[i]) return false; + } - return true; + return true; } function test(test_name, expr) { - let status; - if (expr) { - status = "PASSED"; - } else { - status = "FAILED"; - } - - console.log(`${test_name}: ${status}`); + let status; + if (expr) { + status = 'PASSED'; + } else { + status = 'FAILED'; + } + + console.log(`${test_name}: ${status}`); } -test("colonisers function works", - arraysEqual(colonisers(voyagers), ["Adam family", "Avery family", "Archer family"]) -) \ No newline at end of file +test( + 'colonisers function works', + arraysEqual(colonisers(voyagers), [ 'Adam family', 'Avery family', 'Archer family' ]) +); From 7cf1c65ecb720d2a8b093801f8243fe44a90c654 Mon Sep 17 00:00:00 2001 From: Abdennour Hachemi Date: Mon, 6 Jul 2020 00:59:45 +0100 Subject: [PATCH 60/65] solved --- week-3/2-mandatory/3-space-colonies.js | 1 + 1 file changed, 1 insertion(+) diff --git a/week-3/2-mandatory/3-space-colonies.js b/week-3/2-mandatory/3-space-colonies.js index 7de5dee..be234e0 100644 --- a/week-3/2-mandatory/3-space-colonies.js +++ b/week-3/2-mandatory/3-space-colonies.js @@ -1,4 +1,5 @@ /* + The voyagers decide that they quite like this planet, and some of them want to settle there and colonise it. They call the planet "Alpha" and they decide that the FAMILIES whose last names start with 'A' should stay, while the others go on in search of other planets to call home. From a9692704956f72019681db812d65ffcbfdeccdc5 Mon Sep 17 00:00:00 2001 From: Abdennour Hachemi Date: Mon, 6 Jul 2020 01:02:36 +0100 Subject: [PATCH 61/65] solved --- week-3/2-mandatory/4-eligible-students.js | 66 ++++++++++++----------- 1 file changed, 36 insertions(+), 30 deletions(-) diff --git a/week-3/2-mandatory/4-eligible-students.js b/week-3/2-mandatory/4-eligible-students.js index 6424b01..39d3534 100644 --- a/week-3/2-mandatory/4-eligible-students.js +++ b/week-3/2-mandatory/4-eligible-students.js @@ -7,46 +7,52 @@ - Returns an array containing only the names of the who have attended AT LEAST 8 classes */ -function eligibleStudents() { +function eligibleStudents(arr) { + let accepted = []; + for (var i = 0; i < arr.length; i++) { + if (arr[i][1] >= 8) { + accepted.push(arr[i][0]); + } + } + return accepted; } /* ======= TESTS - DO NOT MODIFY ===== */ const attendances = [ - ["Ahmed", 8], - ["Clement", 10], - ["Elamin", 6], - ["Adam", 7], - ["Tayoa", 11], - ["Nina", 10] -] + [ 'Ahmed', 8 ], + [ 'Clement', 10 ], + [ 'Elamin', 6 ], + [ 'Adam', 7 ], + [ 'Tayoa', 11 ], + [ 'Nina', 10 ] +]; function arraysEqual(a, b) { - if (a === b) return true; - if (a == null || b == null) return false; - if (a.length != b.length) return false; - - for (let i = 0; i < a.length; ++i) { - if (a[i] !== b[i]) return false; - } - - return true; + if (a === b) return true; + if (a == null || b == null) return false; + if (a.length != b.length) return false; + + for (let i = 0; i < a.length; ++i) { + if (a[i] !== b[i]) return false; + } + + return true; } function test(test_name, expr) { - let status; - if (expr) { - status = "PASSED"; - } else { - status = "FAILED"; - } - - console.log(`${test_name}: ${status}`); + let status; + if (expr) { + status = 'PASSED'; + } else { + status = 'FAILED'; + } + + console.log(`${test_name}: ${status}`); } -test("eligibleStudents function works", - arraysEqual( - eligibleStudents(attendances), ["Ahmed", "Clement", "Tayoa", "Nina"] - ) -) \ No newline at end of file +test( + 'eligibleStudents function works', + arraysEqual(eligibleStudents(attendances), [ 'Ahmed', 'Clement', 'Tayoa', 'Nina' ]) +); From 78d6df1da9967a71fe7ab6bdfad1cec36f452115 Mon Sep 17 00:00:00 2001 From: Abdennour Hachemi Date: Mon, 6 Jul 2020 01:04:09 +0100 Subject: [PATCH 62/65] solved --- week-3/2-mandatory/5-journey-planner.js | 87 ++++++++++++++----------- 1 file changed, 48 insertions(+), 39 deletions(-) diff --git a/week-3/2-mandatory/5-journey-planner.js b/week-3/2-mandatory/5-journey-planner.js index 53499c3..880b3cb 100644 --- a/week-3/2-mandatory/5-journey-planner.js +++ b/week-3/2-mandatory/5-journey-planner.js @@ -7,59 +7,68 @@ NOTE: only the names should be returned, not the means of transport. */ -function journeyPlanner() { +function journeyPlanner(location, means) { + let locations = []; + if (means === 'bus') { + for (var i = 0; i < location.length; i++) { + if (location[i].includes('bus')) locations.push(location[i][0]); + } + } else if (means === 'tube') { + for (var i = 0; i < location.length; i++) { + if (location[i].includes('tube')) locations.push(location[i][0]); + } + } else if (means == 'river boat') { + for (var i = 0; i < location.length; i++) { + if (location[i].includes('river boat')) locations.push(location[i][0]); + } + } + return locations; } /* ======= TESTS - DO NOT MODIFY ===== */ const londonLocations = [ - ["Angel", "tube", "bus"], - ["London Bridge", "tube", "river boat"], - ["Tower Bridge", "tube", "bus"], - ["Greenwich", "bus", "river boat"] -] + [ 'Angel', 'tube', 'bus' ], + [ 'London Bridge', 'tube', 'river boat' ], + [ 'Tower Bridge', 'tube', 'bus' ], + [ 'Greenwich', 'bus', 'river boat' ] +]; function arraysEqual(a, b) { - if (a === b) return true; - if (a == null || b == null) return false; - if (a.length != b.length) return false; + if (a === b) return true; + if (a == null || b == null) return false; + if (a.length != b.length) return false; - for (let i = 0; i < a.length; ++i) { - if (a[i] !== b[i]) return false; - } + for (let i = 0; i < a.length; ++i) { + if (a[i] !== b[i]) return false; + } - return true; + return true; } function test(test_name, expr) { - let status; - if (expr) { - status = "PASSED"; - } else { - status = "FAILED"; - } - - console.log(`${test_name}: ${status}`); + let status; + if (expr) { + status = 'PASSED'; + } else { + status = 'FAILED'; + } + + console.log(`${test_name}: ${status}`); } -test("journeyPlanner function works - case 1", - arraysEqual( - journeyPlanner(londonLocations, "river boat"), - ["London Bridge", "Greenwich"] - ) -) +test( + 'journeyPlanner function works - case 1', + arraysEqual(journeyPlanner(londonLocations, 'river boat'), [ 'London Bridge', 'Greenwich' ]) +); -test("journeyPlanner function works - case 2", - arraysEqual( - journeyPlanner(londonLocations, "bus"), - ["Angel", "Tower Bridge", "Greenwich"] - ) -) +test( + 'journeyPlanner function works - case 2', + arraysEqual(journeyPlanner(londonLocations, 'bus'), [ 'Angel', 'Tower Bridge', 'Greenwich' ]) +); -test("journeyPlanner function works - case 3", - arraysEqual( - journeyPlanner(londonLocations, "tube"), - ["Angel", "London Bridge", "Tower Bridge"] - ) -) +test( + 'journeyPlanner function works - case 3', + arraysEqual(journeyPlanner(londonLocations, 'tube'), [ 'Angel', 'London Bridge', 'Tower Bridge' ]) +); From c11ba23112704f2d05780621ee5b8d3a2570e841 Mon Sep 17 00:00:00 2001 From: Abdennour Hachemi Date: Mon, 6 Jul 2020 01:05:02 +0100 Subject: [PATCH 63/65] solved --- week-3/2-mandatory/6-lane-names.js | 52 +++++++++++++----------------- 1 file changed, 22 insertions(+), 30 deletions(-) diff --git a/week-3/2-mandatory/6-lane-names.js b/week-3/2-mandatory/6-lane-names.js index eddfe44..1200bc2 100644 --- a/week-3/2-mandatory/6-lane-names.js +++ b/week-3/2-mandatory/6-lane-names.js @@ -4,43 +4,35 @@ Write a function that will return all street names which contain 'Lane' in their name. */ -function getLanes() { - +function getLanes(array) { + return streetNames.filter(name => name.includes('Lane')); } /* ======= TESTS - DO NOT MODIFY ===== */ -const streetNames = [ - "Abchurch Lane", - "Adam's Court", - "Addle Hill", - "Addle Lane", - "Alban Highwalk" -] +const streetNames = [ 'Abchurch Lane', "Adam's Court", 'Addle Hill', 'Addle Lane', 'Alban Highwalk' ]; function arraysEqual(a, b) { - if (a === b) return true; - if (a == null || b == null) return false; - if (a.length != b.length) return false; - - for (let i = 0; i < a.length; ++i) { - if (a[i] !== b[i]) return false; - } - - return true; + if (a === b) return true; + if (a == null || b == null) return false; + if (a.length != b.length) return false; + + for (let i = 0; i < a.length; ++i) { + if (a[i] !== b[i]) return false; + } + + return true; } - + function test(test_name, expr) { - let status; - if (expr) { - status = "PASSED"; - } else { - status = "FAILED"; - } - - console.log(`${test_name}: ${status}`); + let status; + if (expr) { + status = 'PASSED'; + } else { + status = 'FAILED'; + } + + console.log(`${test_name}: ${status}`); } -test("getLanes function works", - arraysEqual(getLanes(streetNames), ["Abchurch Lane", "Addle Lane"]) -) \ No newline at end of file +test('getLanes function works', arraysEqual(getLanes(streetNames), [ 'Abchurch Lane', 'Addle Lane' ])); From 2e639a473f673b59e28f6f4e1619b9fe845257dd Mon Sep 17 00:00:00 2001 From: Abdennour Hachemi Date: Mon, 6 Jul 2020 01:09:29 +0100 Subject: [PATCH 64/65] solved --- week-3/2-mandatory/7-password-validator.js | 125 ++++++++++++++++----- 1 file changed, 94 insertions(+), 31 deletions(-) diff --git a/week-3/2-mandatory/7-password-validator.js b/week-3/2-mandatory/7-password-validator.js index 57b3d53..a5a47f0 100644 --- a/week-3/2-mandatory/7-password-validator.js +++ b/week-3/2-mandatory/7-password-validator.js @@ -23,47 +23,110 @@ PasswordValidationResult= [false, false, false, false, true] */ function validatePasswords(passwords) { + var validationArray = [ passwords.length ]; + let word; + for (var i = 0; i < passwords.length; i++) { + word = passwords[i]; + if ( + isNotPreviousPassword(i, word, passwords) && + isLong(passwords[i]) && + hasUpperCase(passwords[i]) && + hasLowerCase(passwords[i]) && + hasNumber(passwords[i]) && + hasNoAlphanumeric(passwords[i]) + ) + validationArray[i] = true; + else validationArray[i] = false; + } + return validationArray; } +function isLong(password) { + return password.length >= 5; +} + +function isNotPreviousPassword(i, word, array) { + return i === array.indexOf(word); +} + +function hasUpperCase(string) { + var upperCaseFound = false; + + for (var i = 0; i < string.length; i++) { + if (string.charCodeAt(i) >= 'A'.charCodeAt(0) && string.charCodeAt(i) <= 'Z'.charCodeAt(0)) + upperCaseFound = true; + } + return upperCaseFound; +} +function hasLowerCase(string) { + var lowerCaseFound = false; + + for (var i = 0; i < string.length; i++) { + if (string.charCodeAt(i) >= 'a'.charCodeAt(0) && string.charCodeAt(i) <= 'z'.charCodeAt(0)) + lowerCaseFound = true; + } + return lowerCaseFound; +} +function hasNumber(string) { + var numberFound = false; + + for (var i = 0; i < string.length; i++) { + if (string.charCodeAt(i) >= '0'.charCodeAt(0) && string.charCodeAt(i) <= '9'.charCodeAt(0)) numberFound = true; + } + return numberFound; +} +function hasNoAlphanumeric(string) { + var symbolFound = false; + + for (var i = 0; i < string.length; i++) { + if ( + string.charAt(i) === '!' || + string.charAt(i) === '#' || + string.charAt(i) === '$' || + string.charAt(i) === '%' || + string.charAt(i) === '.' + ) + symbolFound = true; + } + return symbolFound; +} +//Have non - alphanumeric symbols + /* ======= TESTS - DO NOT MODIFY ===== */ -const passwords1 = ["Se%5", "TktE.TJTU", "384#HsHF", "dvyyeyy!5", "tryT3729"] -const passwords2 = ["StUFf27%", "Pl3nty!", "Jai33", "shajsaUA**&&", "Pl3nty!"] +const passwords1 = [ 'Se%5', 'TktE.TJTU', '384#HsHF', 'dvyyeyy!5', 'tryT3729' ]; +const passwords2 = [ 'StUFf27%', 'Pl3nty!', 'Jai33', 'shajsaUA**&&', 'Pl3nty!' ]; function arraysEqual(a, b) { - if (a === b) return true; - if (a == null || b == null) return false; - if (a.length != b.length) return false; - - for (let i = 0; i < a.length; ++i) { - if (a[i] !== b[i]) return false; - } - - return true; + if (a === b) return true; + if (a == null || b == null) return false; + if (a.length != b.length) return false; + + for (let i = 0; i < a.length; ++i) { + if (a[i] !== b[i]) return false; + } + + return true; } function test(test_name, expr) { - let status; - if (expr) { - status = "PASSED"; - } else { - status = "FAILED"; - } - - console.log(`${test_name}: ${status}`); + let status; + if (expr) { + status = 'PASSED'; + } else { + status = 'FAILED'; + } + + console.log(`${test_name}: ${status}`); } test( - "validatePasswords function works - case 1", - arraysEqual( - validatePasswords(passwords1), [false, false, true, false, false] - ) - ); - - test( - "validatePasswords function works - case 2", - arraysEqual( - validatePasswords(passwords2), [true, true, false, false, false] - ) - ); + 'validatePasswords function works - case 1', + arraysEqual(validatePasswords(passwords1), [ false, false, true, false, false ]) +); + +test( + 'validatePasswords function works - case 2', + arraysEqual(validatePasswords(passwords2), [ true, true, false, false, false ]) +); From 436c1e36c1d6d05cf042da8fbbcec3a1052ccba0 Mon Sep 17 00:00:00 2001 From: Abdennour Hachemi Date: Tue, 7 Jul 2020 04:33:34 +0100 Subject: [PATCH 65/65] solved --- week-3/2-mandatory/8-codewars.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/week-3/2-mandatory/8-codewars.md b/week-3/2-mandatory/8-codewars.md index 8bd2b85..c0aa019 100644 --- a/week-3/2-mandatory/8-codewars.md +++ b/week-3/2-mandatory/8-codewars.md @@ -1,4 +1,4 @@ -# Codewars Exercises +# Codewars Exercises => Done. Today, you'll be using a platform called [CodeWars](https://codewars.com) to help you recap the materials you learnt in JS1. CodeWars is an excellent platform for going through interesting JavaScript exercises, and allows you to communicate with the wider community to learn about the best way of writing JavaScript code. @@ -30,4 +30,4 @@ Today, you'll be using a platform called [CodeWars](https://codewars.com) to hel - [people in bus](https://www.codewars.com/kata/number-of-people-in-the-bus/train/javascript) - [sum without highest and lowest](https://www.codewars.com/kata/sum-without-highest-and-lowest-number/train/javascript) - [reveersed array of digits](https://www.codewars.com/kata/convert-number-to-reversed-array-of-digits/train/javascript) -- [slash sum of negatives](https://www.codewars.com/kata/count-of-positives-slash-sum-of-negatives/train/javascript) \ No newline at end of file +- [slash sum of negatives](https://www.codewars.com/kata/count-of-positives-slash-sum-of-negatives/train/javascript)