From 6c893eeaad0c9915477fe3972a14074cda2d8dd5 Mon Sep 17 00:00:00 2001 From: Abdennour Hachemi Date: Thu, 18 Jun 2020 05:41:59 +0100 Subject: [PATCH 01/45] 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/45] 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/45] 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/45] 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/45] 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/45] 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/45] 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/45] 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/45] 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/45] 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/45] 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/45] 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/45] 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/45] 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/45] 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/45] 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/45] 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/45] 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/45] 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/45] 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/45] 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/45] 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/45] 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/45] 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/45] 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/45] 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/45] 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/45] 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/45] 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/45] 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/45] 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/45] 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/45] 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/45] 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/45] 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/45] 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/45] 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/45] 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/45] 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/45] 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/45] 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/45] 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/45] 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/45] 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 88679ff7ada06adc735035a3933c5f78bd97278e Mon Sep 17 00:00:00 2001 From: Abdennour Hachemi Date: Mon, 6 Jul 2020 00:09:17 +0100 Subject: [PATCH 45/45] update week 3 --- .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