From 7178a43079fc2bce16a64c8a0df8d09069d7a3e2 Mon Sep 17 00:00:00 2001 From: osagiestar Date: Mon, 15 Jun 2020 03:12:51 +0100 Subject: [PATCH 01/84] first JS practice --- week-1/1-exercises/C-variables/exercise.js | 6 +++++- week-1/1-exercises/D-strings/exercise.js | 2 +- week-1/2-mandatory/1-syntax-errors.js | 6 +++--- 3 files changed, 9 insertions(+), 5 deletions(-) diff --git a/week-1/1-exercises/C-variables/exercise.js b/week-1/1-exercises/C-variables/exercise.js index a6bbb97..9f876e1 100644 --- a/week-1/1-exercises/C-variables/exercise.js +++ b/week-1/1-exercises/C-variables/exercise.js @@ -1,3 +1,7 @@ // Start by creating a variable `greeting` -console.log(greeting); +var message = "This is a string"; +var messageType = typeof message; + +console.log(message); +console.log(messageType); diff --git a/week-1/1-exercises/D-strings/exercise.js b/week-1/1-exercises/D-strings/exercise.js index 2cffa6a..382eb2f 100644 --- a/week-1/1-exercises/D-strings/exercise.js +++ b/week-1/1-exercises/D-strings/exercise.js @@ -1,3 +1,3 @@ // Start by creating a variable `message` - +let message; console.log(message); diff --git a/week-1/2-mandatory/1-syntax-errors.js b/week-1/2-mandatory/1-syntax-errors.js index 6910f28..44f5f24 100644 --- a/week-1/2-mandatory/1-syntax-errors.js +++ b/week-1/2-mandatory/1-syntax-errors.js @@ -2,15 +2,15 @@ // There are syntax errors in this code - can you fix it to pass the tests? -function addNumbers(a b c) { +function addNumbers(a, b, c) { return a + b + c; } function introduceMe(name, age) -return "Hello, my name is " + name "and I am " age + "years old"; +return "Hello, my name is " + name +" and I am " age + "years old"; function getAddition(a, b) { - total = a ++ b + total = a + b; // Use string interpolation here return "The total is %{total}" From e0e8ecb1da44892ff9534b821984dde5719e22f6 Mon Sep 17 00:00:00 2001 From: osagiestar Date: Mon, 15 Jun 2020 14:40:13 +0100 Subject: [PATCH 02/84] first JS practice --- week-1/1-exercises/C-variables/exercise.js | 29 ++++++++++++++++--- .../1-exercises/F-strings-methods/README.md | 12 +++++--- 2 files changed, 33 insertions(+), 8 deletions(-) diff --git a/week-1/1-exercises/C-variables/exercise.js b/week-1/1-exercises/C-variables/exercise.js index 9f876e1..474855d 100644 --- a/week-1/1-exercises/C-variables/exercise.js +++ b/week-1/1-exercises/C-variables/exercise.js @@ -1,7 +1,28 @@ // Start by creating a variable `greeting` -var message = "This is a string"; -var messageType = typeof message; +// var message = "This is a string"; +// var messageType = typeof message; -console.log(message); -console.log(messageType); +// console.log(message); +// console.log(messageType); + +let greet = "Hello, "; +let message = "my name is Osagie "; +let name = "Osagie"; +let extra = "and the length of my name is "; + +let fullMessage = greet + message; +let fullMessage2 = fullMessage.length; +let messageCase = fullMessage.toUpperCase(); +let nameLength = name.length; +let combined = message + extra + fullMessage2; + +console.log(fullMessage); + +console.log(fullMessage2); + +console.log(messageCase); + +console.log(nameLength); + +console.log(combined); diff --git a/week-1/1-exercises/F-strings-methods/README.md b/week-1/1-exercises/F-strings-methods/README.md index a284654..8743096 100644 --- a/week-1/1-exercises/F-strings-methods/README.md +++ b/week-1/1-exercises/F-strings-methods/README.md @@ -4,7 +4,11 @@ You can find out how many characters there are in a string by using the `length` var name = "Daniel"; var nameLength = name.length; -console.log(nameLength); // Logs 6 +console.log(nameLength); // Logs 6var message = "This is a string"; +// var messageType = typeof message; + +// console.log(message); +// console.log(messageType); ``` You can also get a modified version of a string by calling _string methods_. Let's try one: @@ -20,7 +24,7 @@ You can find out more about string properties and methods by searching for "Java ## Exercise 1 -* Log a message that includes the length of your name +- Log a message that includes the length of your name ## Expected result @@ -30,8 +34,8 @@ My name is Daniel and my name is 6 characters long ## Exercise 2 -* Log the same message using the variable, `name` provided -* Use the `.trim` method to remove the extra whitespace +- Log the same message using the variable, `name` provided +- Use the `.trim` method to remove the extra whitespace ## Expected result From 81ce14a35e3eaeebb67a8ecadf872015bf04b66e Mon Sep 17 00:00:00 2001 From: osagiestar Date: Mon, 15 Jun 2020 15:00:49 +0100 Subject: [PATCH 03/84] a change made --- week-1/1-exercises/C-variables/exercise.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/week-1/1-exercises/C-variables/exercise.js b/week-1/1-exercises/C-variables/exercise.js index 474855d..1b01d56 100644 --- a/week-1/1-exercises/C-variables/exercise.js +++ b/week-1/1-exercises/C-variables/exercise.js @@ -15,7 +15,7 @@ let fullMessage = greet + message; let fullMessage2 = fullMessage.length; let messageCase = fullMessage.toUpperCase(); let nameLength = name.length; -let combined = message + extra + fullMessage2; +let combined = message + extra + nameLength; console.log(fullMessage); From e4ed185320741c6fdf7c2e14e36572c8fe16291e Mon Sep 17 00:00:00 2001 From: osagiestar Date: Mon, 15 Jun 2020 15:55:54 +0100 Subject: [PATCH 04/84] F-strings exercise --- week-1/1-exercises/C-variables/exercise.js | 2 +- week-1/1-exercises/G-numbers/exercise.js | 17 +++++++++++++++++ 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/week-1/1-exercises/C-variables/exercise.js b/week-1/1-exercises/C-variables/exercise.js index 1b01d56..64b3cfa 100644 --- a/week-1/1-exercises/C-variables/exercise.js +++ b/week-1/1-exercises/C-variables/exercise.js @@ -10,8 +10,8 @@ let greet = "Hello, "; let message = "my name is Osagie "; let name = "Osagie"; let extra = "and the length of my name is "; - let fullMessage = greet + message; + let fullMessage2 = fullMessage.length; let messageCase = fullMessage.toUpperCase(); let nameLength = name.length; diff --git a/week-1/1-exercises/G-numbers/exercise.js b/week-1/1-exercises/G-numbers/exercise.js index 49e7bc0..f958dc1 100644 --- a/week-1/1-exercises/G-numbers/exercise.js +++ b/week-1/1-exercises/G-numbers/exercise.js @@ -1 +1,18 @@ // Start by creating a variables `numberOfStudents` and `numberOfMentors` +let name = "Osagie"; + +let intro = "My name is "; +let nameLength = name.length; +let message = + " My name is " + + name + + " and my name is " + + nameLength + + " characters long."; +console.log(nameLength); + +// console.log( +// " My name is " + name + " and my name is " + nameLength + " characters long." +// ); + +console.log(message.trim()); From c376b435bdb95a2e39a512de8306ea4a3a941859 Mon Sep 17 00:00:00 2001 From: osagiestar Date: Mon, 15 Jun 2020 17:38:41 +0100 Subject: [PATCH 05/84] G-numbers exercise --- week-1/1-exercises/G-numbers/exercise.js | 22 ++++++---------------- 1 file changed, 6 insertions(+), 16 deletions(-) diff --git a/week-1/1-exercises/G-numbers/exercise.js b/week-1/1-exercises/G-numbers/exercise.js index f958dc1..7188bcd 100644 --- a/week-1/1-exercises/G-numbers/exercise.js +++ b/week-1/1-exercises/G-numbers/exercise.js @@ -1,18 +1,8 @@ -// Start by creating a variables `numberOfStudents` and `numberOfMentors` -let name = "Osagie"; +let numberOfStudents = 15; +let numberOfMentors = 8; -let intro = "My name is "; -let nameLength = name.length; -let message = - " My name is " + - name + - " and my name is " + - nameLength + - " characters long."; -console.log(nameLength); +let totalOfStudentsAndMentors = numberOfStudents + numberOfMentors; +let message = "Total number of students and mentors: "; -// console.log( -// " My name is " + name + " and my name is " + nameLength + " characters long." -// ); - -console.log(message.trim()); +console.log(message + totalOfStudentsAndMentors); +console.log(`${message}${totalOfStudentsAndMentors}`); From a05a8b9d54f32a2be8fbb6401ac98ad94e6fc0e8 Mon Sep 17 00:00:00 2001 From: osagiestar Date: Tue, 16 Jun 2020 01:09:40 +0100 Subject: [PATCH 06/84] I-floatss exercise --- .vscode/launch.json | 17 +++++++++++++++++ week-1/1-exercises/I-floats/exercise.js | 16 ++++++++++++++++ 2 files changed, 33 insertions(+) create mode 100644 .vscode/launch.json diff --git a/.vscode/launch.json b/.vscode/launch.json new file mode 100644 index 0000000..822e5d1 --- /dev/null +++ b/.vscode/launch.json @@ -0,0 +1,17 @@ +{ + // Use IntelliSense to learn about possible attributes. + // Hover to view descriptions of existing attributes. + // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 + "version": "0.2.0", + "configurations": [ + { + "type": "node", + "request": "launch", + "name": "Launch Program", + "skipFiles": [ + "/**" + ], + "program": "${file}" + } + ] +} \ No newline at end of file diff --git a/week-1/1-exercises/I-floats/exercise.js b/week-1/1-exercises/I-floats/exercise.js index a5bbcd8..4f836c1 100644 --- a/week-1/1-exercises/I-floats/exercise.js +++ b/week-1/1-exercises/I-floats/exercise.js @@ -1,2 +1,18 @@ var numberOfStudents = 15; var numberOfMentors = 8; +let totalofStudentsAndMentors = numberOfStudents + numberOfMentors; + +let percentOfStudents = (numberOfStudents / totalofStudentsAndMentors) * 100; +let percentOfMentors = (numberOfMentors / totalofStudentsAndMentors) * 100; + +let approxPercent = Math.round(percentOfStudents); +let approxPer = Math.round(percentOfMentors); +let comment = "Percentage students :"; + +console.log(percentOfStudents); +console.log(percentOfMentors); + +console.log(approxPercent); +console.log(approxPer); + +console.log(`${comment} ${approxPercent}`); From cd4d58986b5470e5e63c651519104683776c1617 Mon Sep 17 00:00:00 2001 From: osagiestar Date: Tue, 16 Jun 2020 01:29:23 +0100 Subject: [PATCH 07/84] I-floats exercise --- week-1/1-exercises/I-floats/exercise.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/week-1/1-exercises/I-floats/exercise.js b/week-1/1-exercises/I-floats/exercise.js index 4f836c1..2208fbf 100644 --- a/week-1/1-exercises/I-floats/exercise.js +++ b/week-1/1-exercises/I-floats/exercise.js @@ -7,7 +7,8 @@ let percentOfMentors = (numberOfMentors / totalofStudentsAndMentors) * 100; let approxPercent = Math.round(percentOfStudents); let approxPer = Math.round(percentOfMentors); -let comment = "Percentage students :"; +let comment1 = "Percentage students:"; +let comment2 = "Percentage mentors:"; console.log(percentOfStudents); console.log(percentOfMentors); @@ -15,4 +16,5 @@ console.log(percentOfMentors); console.log(approxPercent); console.log(approxPer); -console.log(`${comment} ${approxPercent}`); +console.log(`${comment1} ${approxPercent}%`); +console.log(`${comment2} ${approxPer}%`); From e6a356a2e1f438018b940c89fc6065eeaf340099 Mon Sep 17 00:00:00 2001 From: osagiestar Date: Tue, 16 Jun 2020 06:37:24 +0100 Subject: [PATCH 08/84] J-functionss exercise --- week-1/1-exercises/J-functions/exercise.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/week-1/1-exercises/J-functions/exercise.js b/week-1/1-exercises/J-functions/exercise.js index 0ae5850..040f84e 100644 --- a/week-1/1-exercises/J-functions/exercise.js +++ b/week-1/1-exercises/J-functions/exercise.js @@ -1,7 +1,7 @@ function halve(number) { - // complete the function here + return number / 2; // complete the function here } -var result = halve(12); +let output = halve(12); -console.log(result); +console.log(output); From 38a44474b588623054f632d454dc949e4b5b3754 Mon Sep 17 00:00:00 2001 From: osagiestar Date: Tue, 16 Jun 2020 06:48:45 +0100 Subject: [PATCH 09/84] J-functions exercise2 --- week-1/1-exercises/J-functions/exercise2.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/week-1/1-exercises/J-functions/exercise2.js b/week-1/1-exercises/J-functions/exercise2.js index 82ef5e7..0df95e2 100644 --- a/week-1/1-exercises/J-functions/exercise2.js +++ b/week-1/1-exercises/J-functions/exercise2.js @@ -1,7 +1,7 @@ function triple(number) { - // complete function here + return number * 3; } -var result = triple(12); +let result = triple(12); console.log(result); From be3ab9908a5b510dfd7763c13637b5399c8140a8 Mon Sep 17 00:00:00 2001 From: osagiestar Date: Tue, 16 Jun 2020 09:12:57 +0100 Subject: [PATCH 10/84] K-functions exercise1 --- week-1/1-exercises/K-functions-parameters/exercise.js | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/week-1/1-exercises/K-functions-parameters/exercise.js b/week-1/1-exercises/K-functions-parameters/exercise.js index 8d5db5e..17b86e7 100644 --- a/week-1/1-exercises/K-functions-parameters/exercise.js +++ b/week-1/1-exercises/K-functions-parameters/exercise.js @@ -1,9 +1,7 @@ // Complete the function so that it takes input parameters -function multiply() { - // Calculate the result of the function and return it +function multiply(num1, num2) { + return num1 * num2; } - // Assign the result of calling the function the variable `result` -var result = multiply(3, 4); - +let result = multiply(3, 4); console.log(result); From 88ce31d81717e9168f43af04689ba7529e322584 Mon Sep 17 00:00:00 2001 From: osagiestar Date: Tue, 16 Jun 2020 15:30:56 +0100 Subject: [PATCH 11/84] K-functions exercise2 answer no1 --- week-1/1-exercises/K-functions-parameters/exercise.js | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/week-1/1-exercises/K-functions-parameters/exercise.js b/week-1/1-exercises/K-functions-parameters/exercise.js index 17b86e7..43f2214 100644 --- a/week-1/1-exercises/K-functions-parameters/exercise.js +++ b/week-1/1-exercises/K-functions-parameters/exercise.js @@ -1,7 +1,9 @@ +/*This question interpreted as two numbers, when divided, will give 0.75 as result*/ // Complete the function so that it takes input parameters -function multiply(num1, num2) { - return num1 * num2; + +function divide(num1, num2) { + return (num1 + num2) / 4; } // Assign the result of calling the function the variable `result` -let result = multiply(3, 4); +let result = divide(2, 1); console.log(result); From fc834ac3c5c1ac9c18fe555c03a0d74f2bf23152 Mon Sep 17 00:00:00 2001 From: osagiestar Date: Tue, 16 Jun 2020 15:34:53 +0100 Subject: [PATCH 12/84] K-functions 1-exercise// Complete the function so that it takes input parametersanswer no2 --- week-1/1-exercises/K-functions-parameters/exercise.js | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/week-1/1-exercises/K-functions-parameters/exercise.js b/week-1/1-exercises/K-functions-parameters/exercise.js index 43f2214..e1f07ff 100644 --- a/week-1/1-exercises/K-functions-parameters/exercise.js +++ b/week-1/1-exercises/K-functions-parameters/exercise.js @@ -1,9 +1,9 @@ -/*This question interpreted as two numbers, when divided, will give 0.75 as result*/ -// Complete the function so that it takes input parameters +/*This question is interpreted as two numbers, one dividing the other as below*/ +//Complete the function so that it takes input parameters function divide(num1, num2) { - return (num1 + num2) / 4; + return num1 / num2; } // Assign the result of calling the function the variable `result` -let result = divide(2, 1); -console.log(result); +let output = divide(3, 4); +console.log(output); From 38eef0b2f00999bde576c527288a7598d4dd90b6 Mon Sep 17 00:00:00 2001 From: osagiestar Date: Tue, 16 Jun 2020 16:11:30 +0100 Subject: [PATCH 13/84] K-functions 1-exercise Exercise 3 --- .../K-functions-parameters/exercise.js | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/week-1/1-exercises/K-functions-parameters/exercise.js b/week-1/1-exercises/K-functions-parameters/exercise.js index e1f07ff..078f3e2 100644 --- a/week-1/1-exercises/K-functions-parameters/exercise.js +++ b/week-1/1-exercises/K-functions-parameters/exercise.js @@ -1,9 +1,8 @@ -/*This question is interpreted as two numbers, one dividing the other as below*/ -//Complete the function so that it takes input parameters - -function divide(num1, num2) { - return num1 / num2; +function name() { + returns("Hello, my name is `${name}`"); } -// Assign the result of calling the function the variable `result` -let output = divide(3, 4); -console.log(output); + +var name = "Daniel"; +let greeting = "Hello, my name is"; + +console.log(`${greeting} ${name}`); From d31a1917c37b582828469cec1de937fe77f9e7da Mon Sep 17 00:00:00 2001 From: osagiestar Date: Wed, 17 Jun 2020 16:53:39 +0100 Subject: [PATCH 14/84] syntax debugging --- .../K-functions-parameters/exercise.js | 2 +- week-1/2-mandatory/1-syntax-errors.js | 48 ++++++++++--------- week-1/2-mandatory/2-logic-error.js | 25 ++++++---- 3 files changed, 42 insertions(+), 33 deletions(-) diff --git a/week-1/1-exercises/K-functions-parameters/exercise.js b/week-1/1-exercises/K-functions-parameters/exercise.js index 078f3e2..b71f59a 100644 --- a/week-1/1-exercises/K-functions-parameters/exercise.js +++ b/week-1/1-exercises/K-functions-parameters/exercise.js @@ -2,7 +2,7 @@ function name() { returns("Hello, my name is `${name}`"); } -var name = "Daniel"; +let name = "Osagie"; let greeting = "Hello, my name is"; console.log(`${greeting} ${name}`); diff --git a/week-1/2-mandatory/1-syntax-errors.js b/week-1/2-mandatory/1-syntax-errors.js index 44f5f24..e9339a8 100644 --- a/week-1/2-mandatory/1-syntax-errors.js +++ b/week-1/2-mandatory/1-syntax-errors.js @@ -1,36 +1,40 @@ - - // There are syntax errors in this code - can you fix it to pass the tests? function addNumbers(a, b, c) { - return a + b + c; + return a + b + c; } -function introduceMe(name, age) -return "Hello, my name is " + name +" and I am " age + "years old"; - -function getAddition(a, b) { - total = a + b; +function introduceMe(name, age) { + return "Hello, my name is " + name + " and I am " + age + " years old"; +} - // Use string interpolation here - return "The total is %{total}" +function getRemainder(a, b) { + const remainder = a % b; + return `The remainder is ${remainder}`; } /* ======= TESTS - DO NOT MODIFY ===== */ -// +// // To run these tests type `node 1-syntax-errors.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("fixed addNumbers function - case 1", addNumbers(3,4,6) === 13) -test("fixed introduceMe function", introduceMe("Sonjide",27) === "Hello, my name is Sonjide and I am 27 years old") -test("fixed getRemainder function", getRemainder(23,5) === "The remainder is 3") +test("fixed addNumbers function - case 1", addNumbers(3, 4, 6) === 13); +test( + "fixed introduceMe function", + introduceMe("Sonjide", 27) === + "Hello, my name is Sonjide and I am 27 years old" +); +test( + "fixed getRemainder function", + getRemainder(23, 5) === "The remainder is 3" +); diff --git a/week-1/2-mandatory/2-logic-error.js b/week-1/2-mandatory/2-logic-error.js index 1e0a9d4..3e3d896 100644 --- a/week-1/2-mandatory/2-logic-error.js +++ b/week-1/2-mandatory/2-logic-error.js @@ -1,16 +1,15 @@ // The syntax for this function is valid but it has an error, find it and fix it. function trimWord(word) { - return wordtrim(); + return trimWord(); } function getWordLength(word) { - return "word".length() + return word.length(); } function multiply(a, b, c) { - a * b * c; - return; + return a * b * c; } /* ======= TESTS - DO NOT MODIFY ===== @@ -22,14 +21,20 @@ To run these tests type `node 2-logic-error` into your terminal function test(test_name, expr) { let status; if (expr) { - status = "PASSED" + status = "PASSED"; } else { - status = "FAILED" + status = "FAILED"; } - console.log(`${test_name}: ${status}`) + console.log(`${test_name}: ${status}`); } -test("fixed trimWord function", trimWord(" CodeYourFuture ") === "CodeYourFuture") -test("fixed wordLength function", getWordLength("A wild sentence appeared!") === 25) -test("fixed multiply function", multiply(2,3,6) === 36) \ No newline at end of file +test( + "fixed trimWord function", + trimWord(" CodeYourFuture ") === "CodeYourFuture" +); +test( + "fixed wordLength function", + getWordLength("A wild sentence appeared!") === 25 +); +test("fixed multiply function", multiply(2, 3, 6) === 36); From 06e8051021bc8102777f2ab1b6eed4010faf1d35 Mon Sep 17 00:00:00 2001 From: osagiestar Date: Thu, 18 Jun 2020 00:59:08 +0100 Subject: [PATCH 15/84] parenthesis for trim; none for length --- week-1/2-mandatory/2-logic-error.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/week-1/2-mandatory/2-logic-error.js b/week-1/2-mandatory/2-logic-error.js index 3e3d896..7ef415f 100644 --- a/week-1/2-mandatory/2-logic-error.js +++ b/week-1/2-mandatory/2-logic-error.js @@ -1,11 +1,11 @@ // The syntax for this function is valid but it has an error, find it and fix it. function trimWord(word) { - return trimWord(); + return word.trim(); } function getWordLength(word) { - return word.length(); + return word.length; } function multiply(a, b, c) { From af4b3a68cf6284d787035fef0b78631b95b51b31 Mon Sep 17 00:00:00 2001 From: osagiestar Date: Thu, 18 Jun 2020 04:10:39 +0100 Subject: [PATCH 16/84] function outputs for concatenate --- week-1/2-mandatory/3-function-output.js | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/week-1/2-mandatory/3-function-output.js b/week-1/2-mandatory/3-function-output.js index bbb88a2..9140020 100644 --- a/week-1/2-mandatory/3-function-output.js +++ b/week-1/2-mandatory/3-function-output.js @@ -1,16 +1,18 @@ // Add comments to explain what this function does. You're meant to use Google! -function getNumber() { - return Math.random() * 10; +function letterSet() { + return Math.random() * 10; //Math.random syntax is a floating-point, pseudo-random number between 0 (inclusive) and 1 (exclusive). } // Add comments to explain what this function does. You're meant to use Google! -function s(w1, w2) { - return w1.concat(w2); +function words(w1, w2, w3) { + return w1.concat(w2, w3); // The concat() method is used to join two or more strings. } function concatenate(firstWord, secondWord, thirdWord) { // Write the body of this function to concatenate three words together // Look at the test case below to understand what to expect in return + + return `${firstWord} ${secondWord} ${thirdWord}`; } /* ======= TESTS - DO NOT MODIFY ===== From 5135f7ff0635eca618608b986b903c8dc9d0cfb4 Mon Sep 17 00:00:00 2001 From: osagiestar Date: Fri, 19 Jun 2020 06:38:04 +0100 Subject: [PATCH 17/84] learnt to use toFixed function for adding float to integers --- week-1/2-mandatory/3-function-output.js | 2 +- week-1/2-mandatory/4-tax.js | 19 +++++++++++++++++-- 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/week-1/2-mandatory/3-function-output.js b/week-1/2-mandatory/3-function-output.js index 9140020..088770c 100644 --- a/week-1/2-mandatory/3-function-output.js +++ b/week-1/2-mandatory/3-function-output.js @@ -1,6 +1,6 @@ // Add comments to explain what this function does. You're meant to use Google! function letterSet() { - return Math.random() * 10; //Math.random syntax is a floating-point, pseudo-random number between 0 (inclusive) and 1 (exclusive). + return Math.random() * 10; //Math.random() syntax is a floating-point, pseudo-random number between 0 (inclusive) and 1 (exclusive). } // Add comments to explain what this function does. You're meant to use Google! diff --git a/week-1/2-mandatory/4-tax.js b/week-1/2-mandatory/4-tax.js index 6b84208..dabacd3 100644 --- a/week-1/2-mandatory/4-tax.js +++ b/week-1/2-mandatory/4-tax.js @@ -5,7 +5,14 @@ Sales tax is 20% of the price of the product */ -function calculateSalesTax() {} +/* productPrice is the price before tax*/ +/* salesTaxPercentage is 20% equivalent to 0.20*/ + +function calculateSalesTax(productPrice) { + let salesTaxPercentage = 0.2; + return productPrice + productPrice * salesTaxPercentage; +} +/* function returns salesPrice after tax is added*/ /* CURRENCY FORMATTING @@ -17,7 +24,15 @@ function calculateSalesTax() {} Remember that the prices must include the sales tax (hint: you already wrote a function for this!) */ -function formatCurrency() {} +/* salesPrice is the productPrice + taxValue*/ +/* taxValue is the productPrice * salesTax*/ + +function formatCurrency(productPrice) { + let salesTax = 0.2; + let taxValue = productPrice * salesTax; + let salesPrice = productPrice + taxValue; + return `£${salesPrice.toFixed(2)}`; +} /* ======= TESTS - DO NOT MODIFY ===== There are some Tests in this file that will help you work out if your code is working. From 4b5169eb6f1e17e37df3b5e5952f9ccae81984e6 Mon Sep 17 00:00:00 2001 From: osagiestar Date: Fri, 19 Jun 2020 07:03:25 +0100 Subject: [PATCH 18/84] learnt techniques for concatenation --- week-1/2-mandatory/3-function-output.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/week-1/2-mandatory/3-function-output.js b/week-1/2-mandatory/3-function-output.js index 088770c..c72c4fa 100644 --- a/week-1/2-mandatory/3-function-output.js +++ b/week-1/2-mandatory/3-function-output.js @@ -5,8 +5,9 @@ function letterSet() { // Add comments to explain what this function does. You're meant to use Google! function words(w1, w2, w3) { - return w1.concat(w2, w3); // The concat() method is used to join two or more strings. + return str.concat(w1, w2, w3); // The concat() method is used to join two or more strings. } +/*Option 2: return w1,concat(w2, w3);*/ function concatenate(firstWord, secondWord, thirdWord) { // Write the body of this function to concatenate three words together From 3da6d6dce3c7e3275aaa09e2cc6d8b1a8a1b64e2 Mon Sep 17 00:00:00 2001 From: osagiestar Date: Fri, 19 Jun 2020 07:12:20 +0100 Subject: [PATCH 19/84] learnt techniques for concatenation of strings i.e joining strings together --- week-1/2-mandatory/3-function-output.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/week-1/2-mandatory/3-function-output.js b/week-1/2-mandatory/3-function-output.js index c72c4fa..1afe3f8 100644 --- a/week-1/2-mandatory/3-function-output.js +++ b/week-1/2-mandatory/3-function-output.js @@ -7,7 +7,7 @@ function letterSet() { function words(w1, w2, w3) { return str.concat(w1, w2, w3); // The concat() method is used to join two or more strings. } -/*Option 2: return w1,concat(w2, w3);*/ +/*Option 2: return w1.concat(w2, w3);*/ function concatenate(firstWord, secondWord, thirdWord) { // Write the body of this function to concatenate three words together From bfd8e6030c0fa784d2999697fb1baaf3d786a3d5 Mon Sep 17 00:00:00 2001 From: osagiestar Date: Fri, 19 Jun 2020 07:39:35 +0100 Subject: [PATCH 20/84] test the console.log() syntax --- week-1/1-exercises/B-hello-world/exercise.js | 11 ++++++++++- 1 file changed, 10 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..a644623 100644 --- a/week-1/1-exercises/B-hello-world/exercise.js +++ b/week-1/1-exercises/B-hello-world/exercise.js @@ -1 +1,10 @@ -console.log("Hello world"); +/* console.log() with quotes, single or double, returns the message on the console*/ +// console.log("Hello world. I just started learning JavaScript!"); +// console.log("Hello world. I just started learning JavaScript!"); +// console.log("Hello world. I just started learning JavaScript!"); + +/*Without the quote marks, I see an error message (SyntaxError: missing) */ +// console.log(Hello world. I just started learning JavaScript!); + +/* with just a number and no quotes the output is the number */ +console.log(4); From 78141c00c489041b3290ed85dcd3bb4a375df999 Mon Sep 17 00:00:00 2001 From: osagiestar Date: Fri, 19 Jun 2020 07:45:39 +0100 Subject: [PATCH 21/84] test the console.log() syntax --- week-1/1-exercises/B-hello-world/exercise.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/week-1/1-exercises/B-hello-world/exercise.js b/week-1/1-exercises/B-hello-world/exercise.js index a644623..e137398 100644 --- a/week-1/1-exercises/B-hello-world/exercise.js +++ b/week-1/1-exercises/B-hello-world/exercise.js @@ -1,10 +1,10 @@ /* console.log() with quotes, single or double, returns the message on the console*/ -// console.log("Hello world. I just started learning JavaScript!"); -// console.log("Hello world. I just started learning JavaScript!"); -// console.log("Hello world. I just started learning JavaScript!"); +console.log("Hello world. I just started learning JavaScript!"); +console.log('Hello world. I just started learning JavaScript!'); +console.log("Hello world. I just started learning JavaScript!"); /*Without the quote marks, I see an error message (SyntaxError: missing) */ -// console.log(Hello world. I just started learning JavaScript!); +console.log(Hello world. I just started learning JavaScript!); /* with just a number and no quotes the output is the number */ console.log(4); From ee7a87472e9b68e6d0f5aecae30bf735cd8f8940 Mon Sep 17 00:00:00 2001 From: osagiestar Date: Fri, 19 Jun 2020 08:43:19 +0100 Subject: [PATCH 22/84] create variable aand output result --- week-1/1-exercises/C-variables/exercise.js | 31 ++++------------------ 1 file changed, 5 insertions(+), 26 deletions(-) diff --git a/week-1/1-exercises/C-variables/exercise.js b/week-1/1-exercises/C-variables/exercise.js index 64b3cfa..09f4cd5 100644 --- a/week-1/1-exercises/C-variables/exercise.js +++ b/week-1/1-exercises/C-variables/exercise.js @@ -1,28 +1,7 @@ -// Start by creating a variable `greeting` +/* * */ -// var message = "This is a string"; -// var messageType = typeof message; +let greeting = "Hello world"; -// console.log(message); -// console.log(messageType); - -let greet = "Hello, "; -let message = "my name is Osagie "; -let name = "Osagie"; -let extra = "and the length of my name is "; -let fullMessage = greet + message; - -let fullMessage2 = fullMessage.length; -let messageCase = fullMessage.toUpperCase(); -let nameLength = name.length; -let combined = message + extra + nameLength; - -console.log(fullMessage); - -console.log(fullMessage2); - -console.log(messageCase); - -console.log(nameLength); - -console.log(combined); +console.log(greeting); +console.log(greeting); +console.log(greeting); From 355834fc17001f1ab8fabffa03e3c4314147f4bf Mon Sep 17 00:00:00 2001 From: osagiestar Date: Fri, 19 Jun 2020 08:58:53 +0100 Subject: [PATCH 23/84] learnt how to use (typeof) syntax --- week-1/1-exercises/D-strings/exercise.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/week-1/1-exercises/D-strings/exercise.js b/week-1/1-exercises/D-strings/exercise.js index 382eb2f..2f52b2c 100644 --- a/week-1/1-exercises/D-strings/exercise.js +++ b/week-1/1-exercises/D-strings/exercise.js @@ -1,3 +1,5 @@ // Start by creating a variable `message` -let message; + +let message = "This is a string"; console.log(message); +console.log(typeof message); From 08eee6f7d8c6f86443f4f73c27ed18a1e060a2ec Mon Sep 17 00:00:00 2001 From: osagiestar Date: Fri, 19 Jun 2020 09:07:00 +0100 Subject: [PATCH 24/84] use of + sign to join strings --- week-1/1-exercises/E-strings-concatenation/exercise.js | 5 +++-- 1 file changed, 3 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..c5cba5c 100644 --- a/week-1/1-exercises/E-strings-concatenation/exercise.js +++ b/week-1/1-exercises/E-strings-concatenation/exercise.js @@ -1,3 +1,4 @@ // Start by creating a variable `message` - -console.log(message); +let greeting = "Hello, my name is "; +let name = "Osagie"; +console.log(greeting + name); From 86dfcb85be6fdf6f8657d35d475ca923be2cc0f5 Mon Sep 17 00:00:00 2001 From: osagiestar Date: Fri, 19 Jun 2020 10:29:47 +0100 Subject: [PATCH 25/84] learnt the trim() syntax --- .../1-exercises/F-strings-methods/exercise.js | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/week-1/1-exercises/F-strings-methods/exercise.js b/week-1/1-exercises/F-strings-methods/exercise.js index 2cffa6a..da1aca1 100644 --- a/week-1/1-exercises/F-strings-methods/exercise.js +++ b/week-1/1-exercises/F-strings-methods/exercise.js @@ -1,3 +1,20 @@ // Start by creating a variable `message` +// // Ecercise 1 // +// let name = "Osagie"; +// let namelength = name.length; +// let message = +// "My name is " + name + " and my name is " + namelength + " characters long"; +// console.log(message); + +// Exercise 2 // +let nameWithSpace = " Osagie "; +let nameTrimmed = nameWithSpace.trim(); +let namelength = nameWithSpace.length; +let message = + "My name is " + + nameTrimmed + + " and my name is " + + nameTrimmed.length + + " characters long"; console.log(message); From 0857676de6f071cc622ace16ffe19a9c956e5770 Mon Sep 17 00:00:00 2001 From: osagiestar Date: Fri, 19 Jun 2020 10:45:58 +0100 Subject: [PATCH 26/84] implemented trim() syntax --- week-1/1-exercises/F-strings-methods/exercise.js | 13 +++++++------ week-1/1-exercises/F-strings-methods/exercise2.js | 10 +++++++++- 2 files changed, 16 insertions(+), 7 deletions(-) diff --git a/week-1/1-exercises/F-strings-methods/exercise.js b/week-1/1-exercises/F-strings-methods/exercise.js index da1aca1..cd21087 100644 --- a/week-1/1-exercises/F-strings-methods/exercise.js +++ b/week-1/1-exercises/F-strings-methods/exercise.js @@ -1,13 +1,14 @@ // Start by creating a variable `message` -// // Ecercise 1 // -// let name = "Osagie"; -// let namelength = name.length; -// let message = -// "My name is " + name + " and my name is " + namelength + " characters long"; -// console.log(message); +// Ecercise 1 // +let name = "Osagie"; +let namelength = name.length; +let message = + "My name is " + name + " and my name is " + namelength + " characters long"; +console.log(message); // Exercise 2 // +// For this exercise, I made spaces before and after name// let nameWithSpace = " Osagie "; let nameTrimmed = nameWithSpace.trim(); let namelength = nameWithSpace.length; diff --git a/week-1/1-exercises/F-strings-methods/exercise2.js b/week-1/1-exercises/F-strings-methods/exercise2.js index b4b4694..035ef53 100644 --- a/week-1/1-exercises/F-strings-methods/exercise2.js +++ b/week-1/1-exercises/F-strings-methods/exercise2.js @@ -1,3 +1,11 @@ +// Exercise 2 // const name = " Daniel "; - +let nameTrimmed = name.trim(); +let namelength = nameTrimmed.length; +let message = + "My name is " + + nameTrimmed + + " and my name is " + + nameTrimmed.length + + " characters long"; console.log(message); From b949687cd23942759a2797f3b1c74d213dab469a Mon Sep 17 00:00:00 2001 From: osagiestar Date: Fri, 19 Jun 2020 11:28:11 +0100 Subject: [PATCH 27/84] use of Math.round to convert floats/decimal numbers to whole integers --- week-1/1-exercises/I-floats/exercise.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/week-1/1-exercises/I-floats/exercise.js b/week-1/1-exercises/I-floats/exercise.js index 2208fbf..ca1bc08 100644 --- a/week-1/1-exercises/I-floats/exercise.js +++ b/week-1/1-exercises/I-floats/exercise.js @@ -10,11 +10,11 @@ let approxPer = Math.round(percentOfMentors); let comment1 = "Percentage students:"; let comment2 = "Percentage mentors:"; -console.log(percentOfStudents); -console.log(percentOfMentors); +// console.log(percentOfStudents); +// console.log(percentOfMentors); -console.log(approxPercent); -console.log(approxPer); +// console.log(approxPercent); +// console.log(approxPer); console.log(`${comment1} ${approxPercent}%`); console.log(`${comment2} ${approxPer}%`); From b4fd2969576182fb1b61c57dfa6b8e337837eafd Mon Sep 17 00:00:00 2001 From: osagiestar Date: Fri, 19 Jun 2020 12:29:06 +0100 Subject: [PATCH 28/84] calling a function --- week-1/1-exercises/J-functions/exercise.js | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/week-1/1-exercises/J-functions/exercise.js b/week-1/1-exercises/J-functions/exercise.js index 040f84e..6198c17 100644 --- a/week-1/1-exercises/J-functions/exercise.js +++ b/week-1/1-exercises/J-functions/exercise.js @@ -3,5 +3,9 @@ function halve(number) { } let output = halve(12); +let result = halve(50); +let value = halve(36); console.log(output); +console.log(result); +console.log(value); From cc4aa985c47551cde12be1e3fdba63114da2b5e4 Mon Sep 17 00:00:00 2001 From: osagiestar Date: Sat, 20 Jun 2020 05:19:48 +0100 Subject: [PATCH 29/84] declare a function first and then call the function using console.log() --- .../1-exercises/K-functions-parameters/exercise.js | 13 ++++++------- .../1-exercises/K-functions-parameters/exercise2.js | 6 ++++-- .../1-exercises/K-functions-parameters/exercise3.js | 11 +++++++---- .../1-exercises/K-functions-parameters/exercise4.js | 10 ++++++++-- .../1-exercises/K-functions-parameters/exercise5.js | 11 +++++++---- 5 files changed, 32 insertions(+), 19 deletions(-) diff --git a/week-1/1-exercises/K-functions-parameters/exercise.js b/week-1/1-exercises/K-functions-parameters/exercise.js index b71f59a..808c5bd 100644 --- a/week-1/1-exercises/K-functions-parameters/exercise.js +++ b/week-1/1-exercises/K-functions-parameters/exercise.js @@ -1,8 +1,7 @@ -function name() { - returns("Hello, my name is `${name}`"); -} - -let name = "Osagie"; -let greeting = "Hello, my name is"; +// multiplication function// -console.log(`${greeting} ${name}`); +function multiply() { + return 3 * 4; +} +let result = multiply(3, 4); +console.log(result); diff --git a/week-1/1-exercises/K-functions-parameters/exercise2.js b/week-1/1-exercises/K-functions-parameters/exercise2.js index db7a890..a2ddcdd 100644 --- a/week-1/1-exercises/K-functions-parameters/exercise2.js +++ b/week-1/1-exercises/K-functions-parameters/exercise2.js @@ -1,5 +1,7 @@ // Declare your function first - -var result = divide(3, 4); +function divide() { + return 3 / 4; +} +let result = divide(); console.log(result); diff --git a/week-1/1-exercises/K-functions-parameters/exercise3.js b/week-1/1-exercises/K-functions-parameters/exercise3.js index 537e9f4..ae17d21 100644 --- a/week-1/1-exercises/K-functions-parameters/exercise3.js +++ b/week-1/1-exercises/K-functions-parameters/exercise3.js @@ -1,5 +1,8 @@ // Write your function here - -var greeting = createGreeting("Daniel"); - -console.log(greeting); +function createGreeting() { + let name = "Daniel"; + let greeting = "Hello, my name is "; + let fullGreeting = greeting + name; + return fullGreeting; +} +console.log(createGreeting()); diff --git a/week-1/1-exercises/K-functions-parameters/exercise4.js b/week-1/1-exercises/K-functions-parameters/exercise4.js index 7ab4458..6cff3ee 100644 --- a/week-1/1-exercises/K-functions-parameters/exercise4.js +++ b/week-1/1-exercises/K-functions-parameters/exercise4.js @@ -1,5 +1,11 @@ // Declare your function first - +function sum() { + return 13 + 124; + // let num1 = 13; + // let num2 = 124; + // let addition = 13 + 124; + // return addition; +} // Call the function and assign to a variable `sum` -console.log(sum); +console.log(sum()); diff --git a/week-1/1-exercises/K-functions-parameters/exercise5.js b/week-1/1-exercises/K-functions-parameters/exercise5.js index 7c5bcd6..0672756 100644 --- a/week-1/1-exercises/K-functions-parameters/exercise5.js +++ b/week-1/1-exercises/K-functions-parameters/exercise5.js @@ -1,5 +1,8 @@ // Declare your function here - -const greeting = createLongGreeting("Daniel", 30); - -console.log(greeting); +function createLongGreeting() { + let name = "Daniel"; + let age = 30; + const greeting = `My name is ${name} and I'm ${age} years old`; + return greeting; +} +console.log(createLongGreeting()); From 525d69602b1a8d5017ae283e8830aca4eccaa5a5 Mon Sep 17 00:00:00 2001 From: osagiestar Date: Sat, 20 Jun 2020 06:43:25 +0100 Subject: [PATCH 30/84] more work to be done --- week-1/3-extra/1-currency-conversion.js | 10 +++++-- week-1/3-extra/2-piping.js | 38 +++++++++++++------------ 2 files changed, 28 insertions(+), 20 deletions(-) diff --git a/week-1/3-extra/1-currency-conversion.js b/week-1/3-extra/1-currency-conversion.js index 7f321d9..0ed6c27 100644 --- a/week-1/3-extra/1-currency-conversion.js +++ b/week-1/3-extra/1-currency-conversion.js @@ -5,7 +5,9 @@ Write a function that converts a price to USD (exchange rate is 1.4 $ to £) */ -function convertToUSD() {} +function convertToUSD(pound) { + return pound * 1.4; +} /* CURRENCY FORMATTING @@ -16,7 +18,11 @@ function convertToUSD() {} Find a way to add 1% to all currency conversions (think about the DRY principle) */ -function convertToBRL() {} +function convertToBRL(pound) { + let convert = pound * 5.7; + let interest = convert * 0.01; + return convert + interest; +} /* ======= TESTS - DO NOT MODIFY ===== There are some Tests in this file that will help you work out if your code is working. diff --git a/week-1/3-extra/2-piping.js b/week-1/3-extra/2-piping.js index 93c0bf7..e2b4f4f 100644 --- a/week-1/3-extra/2-piping.js +++ b/week-1/3-extra/2-piping.js @@ -16,26 +16,28 @@ the final result to the variable goodCode */ -function add() { - +function add(pipe1, pipe2) { + return pipe1 + pipe2; } -function multiply() { - +function multiply(pipe1, pipe2) { + return pipe1 * pipe2; } -function format() { - +function format(pound) { + return `£${pound}`; } -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)); //badCode has all codes mumbled up in one line// /* BETTER PRACTICE */ -let goodCode = +let sum = add(startingValue, 10); +let product = multiply(sum, 2); +let goodCode = format(product); /* ======= TESTS - DO NOT MODIFY ===== There are some Tests in this file that will help you work out if your code is working. @@ -46,17 +48,17 @@ To run these tests type `node 2-piping.js` into your terminal function test(test_name, expr) { let status; if (expr) { - status = "PASSED" + status = "PASSED"; } else { - status = "FAILED" + status = "FAILED"; } - console.log(`${test_name}: ${status}`) + 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 c68d50fdcc3bb82c3166ee9e03dc166b0c5562f0 Mon Sep 17 00:00:00 2001 From: osagiestar Date: Sat, 20 Jun 2020 08:12:11 +0100 Subject: [PATCH 31/84] learnt function in a function method --- .../L-functions-nested/exercise.js | 30 +++++++++++++++---- 1 file changed, 25 insertions(+), 5 deletions(-) diff --git a/week-1/1-exercises/L-functions-nested/exercise.js b/week-1/1-exercises/L-functions-nested/exercise.js index a5d3774..fc89a87 100644 --- a/week-1/1-exercises/L-functions-nested/exercise.js +++ b/week-1/1-exercises/L-functions-nested/exercise.js @@ -1,5 +1,25 @@ -var mentor1 = "Daniel"; -var mentor2 = "Irina"; -var mentor3 = "Mimi"; -var mentor4 = "Rob"; -var mentor5 = "Yohannes"; +//Exercise 1// +function percentProgram(firstNumber, secondNumber) { + let overallTotal = firstNumber + secondNumber; + + let percentage = Math.floor((firstNumber / overallTotal) * 100); + return percentage; +} + +function message(numberOfStudents, numberOfMentors) { + let percentOfStudents = percentProgram(numberOfStudents, numberOfMentors); + let percentOfMentors = percentProgram(numberOfMentors, numberOfStudents); + let fullMessage = `Percentage students: ${percentOfStudents}% and Percentage mentors: ${percentOfMentors}%`; + return fullMessage; +} +let finalMessage = message(15, 8); +console.log(finalMessage); + +// console.log(`${comment1} ${approxPercent}%`); +// console.log(`${comment2} ${approxPer}%`); + +// var mentor1 = "Daniel"; +// var mentor2 = "Irina"; +// var mentor3 = "Mimi"; +// var mentor4 = "Rob"; +// var mentor5 = "Yohannes"; From 4083bf9ff0bfbe6feb4d8ed3763e5dc0c263171b Mon Sep 17 00:00:00 2001 From: osagiestar Date: Mon, 22 Jun 2020 15:56:12 +0100 Subject: [PATCH 32/84] setting boolean conditions --- week-2/1-exercises/B-boolean-literals/exercise.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/week-2/1-exercises/B-boolean-literals/exercise.js b/week-2/1-exercises/B-boolean-literals/exercise.js index 6c5060f..4a1b1e5 100644 --- a/week-2/1-exercises/B-boolean-literals/exercise.js +++ b/week-2/1-exercises/B-boolean-literals/exercise.js @@ -5,7 +5,10 @@ Add the required variables with the correct boolean values assigned. */ -var codeYourFutureIsGreat = true; +let codeYourFutureIsGreat = true; +let mozafarIsCool = true; +let calculationCorrect = true; +let moreThan10Students = true; /* DO NOT EDIT BELOW THIS LINE From de1c5a9554ff1256c6af9b497e6417402f71a524 Mon Sep 17 00:00:00 2001 From: osagiestar Date: Mon, 22 Jun 2020 23:49:40 +0100 Subject: [PATCH 33/84] used comparison operators --- .github/pull_request_template.md | 10 +++++----- week-2/1-exercises/B-boolean-literals/exercise.js | 4 ++-- .../1-exercises/C-comparison-operators/exercise.js | 12 ++++++------ 3 files changed, 13 insertions(+), 13 deletions(-) diff --git a/.github/pull_request_template.md b/.github/pull_request_template.md index 696fd85..4cb5a22 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: Osagie Okoedo +Your City: Birmingham +Your Slack Name: Osagie Okoedo # Homework Details -Module: -Week: +Module: JavaScript +Week: 1 diff --git a/week-2/1-exercises/B-boolean-literals/exercise.js b/week-2/1-exercises/B-boolean-literals/exercise.js index 4a1b1e5..89c3726 100644 --- a/week-2/1-exercises/B-boolean-literals/exercise.js +++ b/week-2/1-exercises/B-boolean-literals/exercise.js @@ -6,9 +6,9 @@ */ let codeYourFutureIsGreat = true; -let mozafarIsCool = true; +let mozafarIsCool = false; let calculationCorrect = true; -let moreThan10Students = true; +let moreThan10Students = false; /* DO NOT EDIT BELOW THIS LINE diff --git a/week-2/1-exercises/C-comparison-operators/exercise.js b/week-2/1-exercises/C-comparison-operators/exercise.js index 58aee1c..19af43e 100644 --- a/week-2/1-exercises/C-comparison-operators/exercise.js +++ b/week-2/1-exercises/C-comparison-operators/exercise.js @@ -5,16 +5,16 @@ The variables should have values that match the expected results. */ -var studentCount = 16; -var mentorCount = 9; -var moreStudentsThanMentors; // finish this statement +let studentCount = 16; +let mentorCount = 9; +let moreStudentsThanMentors = studentCount > mentorCount; // finish this statement -var roomMaxCapacity = 25; -var enoughSpaceInRoom; // finish this statement +let roomMaxCapacity = 25; +let enoughSpaceInRoom = roomMaxCapacity <= 25; // 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 c2bc5cbf791f08924f85b9ff258f54da02957800 Mon Sep 17 00:00:00 2001 From: osagiestar Date: Tue, 23 Jun 2020 00:26:36 +0100 Subject: [PATCH 34/84] using true or false rules --- week-2/1-exercises/B-boolean-literals/exercise.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/week-2/1-exercises/B-boolean-literals/exercise.js b/week-2/1-exercises/B-boolean-literals/exercise.js index 89c3726..6c675b9 100644 --- a/week-2/1-exercises/B-boolean-literals/exercise.js +++ b/week-2/1-exercises/B-boolean-literals/exercise.js @@ -5,7 +5,7 @@ Add the required variables with the correct boolean values assigned. */ -let codeYourFutureIsGreat = true; +let codeYourFutureIsGreat = true; //Ofcourse, CYF is great// let mozafarIsCool = false; let calculationCorrect = true; let moreThan10Students = false; From 2a27ae368dca32313955b20dd0731ec67c9474ad Mon Sep 17 00:00:00 2001 From: osagiestar Date: Tue, 23 Jun 2020 00:47:41 +0100 Subject: [PATCH 35/84] setting condition for console.log match reuslt --- week-2/1-exercises/D-predicates/exercise.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/week-2/1-exercises/D-predicates/exercise.js b/week-2/1-exercises/D-predicates/exercise.js index f600521..01fc6a7 100644 --- a/week-2/1-exercises/D-predicates/exercise.js +++ b/week-2/1-exercises/D-predicates/exercise.js @@ -4,15 +4,16 @@ Write a predicate to predicates The variables should have values that match the expected results. */ +var number = 5; // Finish the predicate function to test if the passed number is negative (less than zero) function isNegative(number) { - + return numberNegative < 0; } // Finish the predicate function to test if the passed number is between 0 and 10 function isBetweenZeroAnd10(number) { - + return number > 1 && number < 10; } /* @@ -32,4 +33,3 @@ console.log("Is the number between 0 and 10? " + numberBetweenZeroAnd10); Is the number negative? false Is the number between 0 and 10? true */ - From 0bb140c623bde904b865f33ea00046a5b1b0119a Mon Sep 17 00:00:00 2001 From: osagiestar Date: Tue, 23 Jun 2020 01:37:12 +0100 Subject: [PATCH 36/84] used array --- week-2/1-exercises/E-conditionals/exercise.js | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/week-2/1-exercises/E-conditionals/exercise.js b/week-2/1-exercises/E-conditionals/exercise.js index acbaaa8..b26b0c8 100644 --- a/week-2/1-exercises/E-conditionals/exercise.js +++ b/week-2/1-exercises/E-conditionals/exercise.js @@ -5,10 +5,16 @@ If Daniel is a mentor, print out "Hi, I'm Daniel, I'm a mentor." If Daniel is a student, print out "Hi, I'm Daniel, I'm a student." */ - -var name = "Daniel"; -var danielsRole = "mentor"; - +function status() { + var name = "Daniel"; + var danielsRole = [["mentor"], ["student"]]; + if (danielsRole === danielsRole[0]) { + return "Hi, I'm Daniel, I'm a mentor"; + } + return "Hi, I'm Daniel, I'm a student."; +} +let output = "Hi, I'm Daniel, I'm a mentor"; +console.log(output); /* EXPECTED RESULT --------------- From 5c5edc3458d560c81f2ed203e05488e09dd08a7d Mon Sep 17 00:00:00 2001 From: osagiestar Date: Tue, 23 Jun 2020 14:10:43 +0100 Subject: [PATCH 37/84] AND and OR logic --- week-2/1-exercises/F-logical-operators/exercise.js | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 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..90b903f 100644 --- a/week-2/1-exercises/F-logical-operators/exercise.js +++ b/week-2/1-exercises/F-logical-operators/exercise.js @@ -11,14 +11,15 @@ 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; + +let htmlLevelAbove5 = htmlLevel > 5; +let cssLevelAbove5 = cssLevel > 5; // Finish the next two statement // Use the previous variables and logical operators // Do not "hardcode" the answers -var cssAndHtmlAbove5; -var cssOrHtmlAbove5; +let cssAndHtmlAbove5 = cssLevel > 5 && htmlLevel; +let cssOrHtmlAbove5 = cssLevel > 5 || htmlLevel > 5; /* DO NOT EDIT BELOW THIS LINE @@ -27,10 +28,7 @@ var cssOrHtmlAbove5; console.log("Is Html knowledge above 5?", htmlLevelAbove5); console.log("Is CSS knowledge above 5?", cssLevelAbove5); console.log("Is Html And CSS knowledge above 5?", cssAndHtmlAbove5); -console.log( - "Is either Html or CSS knowledge above 5?", - cssOrHtmlAbove5 -); +console.log("Is either Html or CSS knowledge above 5?", cssOrHtmlAbove5); /* EXPECTED RESULT From 5aac1a94fe446b1696c9d64de63833488f33dfa8 Mon Sep 17 00:00:00 2001 From: Osagie Okoedo Date: Tue, 23 Jun 2020 17:10:52 +0100 Subject: [PATCH 38/84] passed first task, the rest to be continued... --- week-2/2-mandatory/2-function-creation.js | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/week-2/2-mandatory/2-function-creation.js b/week-2/2-mandatory/2-function-creation.js index bf7ecfd..4c3e177 100644 --- a/week-2/2-mandatory/2-function-creation.js +++ b/week-2/2-mandatory/2-function-creation.js @@ -5,8 +5,20 @@ Write a function that: - removes any forward slashes (/) in the strings - makes the string all lowercase */ -function tidyUpString(strArr) {} +function tidyUpString(strArr) { + let trimString; + let removeSlash; + let convertToLowerCase; + for (let i = 0; i < strArr.length; i++) { + trimString = strArr[i].trim(); + removeSlash = trimString.replace("/", ""); + convertToLowerCase = removeSlash.toLowerCase(); + strArr[i] = convertToLowerCase; + } + return strArr; +} +//trim(), toLowerCase() and replace("/", "") /* Complete the function to check if the variable `num` satisfies the following requirements: - is a number From 5ced16bc966a8ae8f3cd80b020ed8e891feaad9b Mon Sep 17 00:00:00 2001 From: osagiestar Date: Wed, 24 Jun 2020 01:01:12 +0100 Subject: [PATCH 39/84] added omitted sign > and value 5 --- week-2/1-exercises/F-logical-operators/exercise.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/week-2/1-exercises/F-logical-operators/exercise.js b/week-2/1-exercises/F-logical-operators/exercise.js index 90b903f..fd2e2b1 100644 --- a/week-2/1-exercises/F-logical-operators/exercise.js +++ b/week-2/1-exercises/F-logical-operators/exercise.js @@ -18,7 +18,7 @@ let cssLevelAbove5 = cssLevel > 5; // Finish the next two statement // Use the previous variables and logical operators // Do not "hardcode" the answers -let cssAndHtmlAbove5 = cssLevel > 5 && htmlLevel; +let cssAndHtmlAbove5 = cssLevel > 5 && htmlLevel > 5; let cssOrHtmlAbove5 = cssLevel > 5 || htmlLevel > 5; /* From 86c0047647aa2ddd05a2441c457fe72063e3de16 Mon Sep 17 00:00:00 2001 From: osagiestar Date: Wed, 24 Jun 2020 01:20:36 +0100 Subject: [PATCH 40/84] logical operator application --- .../F-logical-operators/exercise2.js | 28 ++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) diff --git a/week-2/1-exercises/F-logical-operators/exercise2.js b/week-2/1-exercises/F-logical-operators/exercise2.js index 6f4199c..bff3ce2 100644 --- a/week-2/1-exercises/F-logical-operators/exercise2.js +++ b/week-2/1-exercises/F-logical-operators/exercise2.js @@ -5,7 +5,33 @@ Update the code so that you get the expected result. */ -function isNegative() {} +function isNegative(number) { + if (number < 0) { + return true; + } + return false; +} + +function isBetween5and10(number) { + if (number >= 5 && number <= 10) { + return true; + } + return false; +} + +function isShortName(name) { + if (name.length < 7) { + return true; + } + return false; +} + +function startsWithD(name) { + if (name[0] === "D") { + return true; + } + return false; +} /* DO NOT EDIT BELOW THIS LINE From c0527cc904d90b040d399694fdd368f15bfe9fec Mon Sep 17 00:00:00 2001 From: osagiestar Date: Wed, 24 Jun 2020 01:52:04 +0100 Subject: [PATCH 41/84] returns a string values --- week-2/1-exercises/G-conditionals-2/exercise-1.js | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) 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..e1b6681 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"; + } } /* From cd61d5a231f424b0491bb54456f1a5a356ae53ae Mon Sep 17 00:00:00 2001 From: osagiestar Date: Wed, 24 Jun 2020 01:59:28 +0100 Subject: [PATCH 42/84] takes numbers and return string values --- week-2/1-exercises/G-conditionals-2/exercise-1.js | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) 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 e1b6681..2de593b 100644 --- a/week-2/1-exercises/G-conditionals-2/exercise-1.js +++ b/week-2/1-exercises/G-conditionals-2/exercise-1.js @@ -6,10 +6,20 @@ - if number is more or equal to zero, return the word "positive" */ +// function negativeOrPositive(number) { +// if (number < 0) { +// return "negative"; +// } else if (number >= 0) { +// return "positive"; +// } +// } + +/*OR*/ function negativeOrPositive(number) { if (number < 0) { return "negative"; - } else if (number >= 0) { + } + if (number >= 0) { return "positive"; } } From 111b28923dc798c045434edb0b2b279c06399d88 Mon Sep 17 00:00:00 2001 From: osagiestar Date: Wed, 24 Jun 2020 02:05:35 +0100 Subject: [PATCH 43/84] pass test program --- .../G-conditionals-2/exercise-1.js | 22 +++++++++---------- .../G-conditionals-2/exercise-2.js | 13 +++++++---- 2 files changed, 20 insertions(+), 15 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 2de593b..b106610 100644 --- a/week-2/1-exercises/G-conditionals-2/exercise-1.js +++ b/week-2/1-exercises/G-conditionals-2/exercise-1.js @@ -6,24 +6,24 @@ - if number is more or equal to zero, return the word "positive" */ -// function negativeOrPositive(number) { -// if (number < 0) { -// return "negative"; -// } else if (number >= 0) { -// return "positive"; -// } -// } - -/*OR*/ function negativeOrPositive(number) { if (number < 0) { return "negative"; - } - if (number >= 0) { + } else if (number >= 0) { return "positive"; } } +/*OR*/ +// function negativeOrPositive(number) { +// if (number < 0) { +// return "negative"; +// } +// if (number >= 0) { +// return "positive"; +// } +// } + /* DO NOT EDIT BELOW THIS LINE --------------------------- */ 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..9d12416 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,12 @@ */ function studentPassed(grade) { - + if (grade < 50) { + return "failed"; + } + if (grade >= 50) { + return "passed"; + } } /* @@ -18,9 +23,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 3416a3d7759ca35aa722d9957e104902e59e486c Mon Sep 17 00:00:00 2001 From: osagiestar Date: Wed, 24 Jun 2020 02:20:58 +0100 Subject: [PATCH 44/84] takes a number and outputs a result --- week-2/1-exercises/G-conditionals-2/exercise-1.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 b106610..8cce2dc 100644 --- a/week-2/1-exercises/G-conditionals-2/exercise-1.js +++ b/week-2/1-exercises/G-conditionals-2/exercise-1.js @@ -14,7 +14,7 @@ function negativeOrPositive(number) { } } -/*OR*/ +/*An Alternative/ // function negativeOrPositive(number) { // if (number < 0) { // return "negative"; From 03d992d02ee762a0d8b5d3cf915f9555803029b9 Mon Sep 17 00:00:00 2001 From: osagiestar Date: Wed, 24 Jun 2020 02:36:11 +0100 Subject: [PATCH 45/84] grading result function --- week-2/1-exercises/G-conditionals-2/exercise-3.js | 11 +++++++++-- 1 file changed, 9 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..d39150d 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,14 @@ */ function calculateGrade(mark) { - + if (mark >= 80) { + return "A"; + } else if (mark > 60 && mark < 80) { + return "B"; + } else if ((mark = 60 || mark < 50)) { + return "C"; + } + return "F"; } /* @@ -25,7 +32,7 @@ console.log("'" + grade2 + "': " + calculateGrade(grade2)); console.log("'" + grade3 + "': " + calculateGrade(grade3)); console.log("'" + grade4 + "': " + calculateGrade(grade4)); - /* +/* EXPECTED RESULT --------------- '49': F From ee9af80dda91e2d9fb8d9aae82a2b39868a09a0e Mon Sep 17 00:00:00 2001 From: osagiestar Date: Wed, 24 Jun 2020 02:50:39 +0100 Subject: [PATCH 46/84] learnt the use of str.includes() --- week-2/1-exercises/G-conditionals-2/exercise-4.js | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 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..8f3e50e 100644 --- a/week-2/1-exercises/G-conditionals-2/exercise-4.js +++ b/week-2/1-exercises/G-conditionals-2/exercise-4.js @@ -9,7 +9,10 @@ */ function containsCode(sentence) { - + if (sentence.includes("code")) { + return true; + } + return false; } /* @@ -19,11 +22,11 @@ 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 12f46210c586ab54d9cfc3179248382fed78d655 Mon Sep 17 00:00:00 2001 From: osagiestar Date: Wed, 24 Jun 2020 03:15:07 +0100 Subject: [PATCH 47/84] array of strings and numbers --- week-2/1-exercises/H-array-literals/exercise.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/week-2/1-exercises/H-array-literals/exercise.js b/week-2/1-exercises/H-array-literals/exercise.js index d6dc556..9826af8 100644 --- a/week-2/1-exercises/H-array-literals/exercise.js +++ b/week-2/1-exercises/H-array-literals/exercise.js @@ -4,8 +4,8 @@ Declare some variables assigned to arrays of values */ -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 +var numbers = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]; // add numbers from 1 to 10 into this array +var mentors = ["Daniel", "Irina", "Rares"]; // Create an array with the names of the mentors: Daniel, Irina and Rares /* DO NOT EDIT BELOW THIS LINE From c86035cc27d748d8ea76caaa9a25bf18f17593e0 Mon Sep 17 00:00:00 2001 From: osagiestar Date: Wed, 24 Jun 2020 04:00:50 +0100 Subject: [PATCH 48/84] arr.lengthproperty --- week-2/1-exercises/I-array-properties/exercise.js | 7 +++++-- 1 file changed, 5 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..f7cceb6 100644 --- a/week-2/1-exercises/I-array-properties/exercise.js +++ b/week-2/1-exercises/I-array-properties/exercise.js @@ -5,8 +5,11 @@ */ -function isEmpty(arr) { - return; // complete this statement +function isEmpty(names, numbers) { + if (names.length === 0) { + return true; // complete this statement + } + return false; } /* From 48e81d0083da1828f349d585c207cda7405fa50a Mon Sep 17 00:00:00 2001 From: osagiestar Date: Wed, 24 Jun 2020 04:49:15 +0100 Subject: [PATCH 49/84] array 1st and last values --- week-2/1-exercises/J-array-get-set/exercise.js | 4 ++-- 1 file changed, 2 insertions(+), 2 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..18d072c 100644 --- a/week-2/1-exercises/J-array-get-set/exercise.js +++ b/week-2/1-exercises/J-array-get-set/exercise.js @@ -5,11 +5,11 @@ */ 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 } /* From 67329ae7c115c1310e6a5b2920a9417cc65686a4 Mon Sep 17 00:00:00 2001 From: osagiestar Date: Wed, 24 Jun 2020 06:01:50 +0100 Subject: [PATCH 50/84] push() function to add to the end of an index list --- week-2/1-exercises/J-array-get-set/exercises2.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) 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..fad6e6b 100644 --- a/week-2/1-exercises/J-array-get-set/exercises2.js +++ b/week-2/1-exercises/J-array-get-set/exercises2.js @@ -6,7 +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 +let numbers = [1, 2, 3]; // Don't change this array literal declaration +numbers.push(4); +numbers[0] = 1; /* DO NOT EDIT BELOW THIS LINE From 0de33504f4f224d7b857440c13cc4a36a0f0f94b Mon Sep 17 00:00:00 2001 From: Osagie Okoedo Date: Wed, 24 Jun 2020 17:34:50 +0100 Subject: [PATCH 51/84] still working on the other questions --- week-2/2-mandatory/1-fix-functions.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/week-2/2-mandatory/1-fix-functions.js b/week-2/2-mandatory/1-fix-functions.js index 6316fad..23adcf3 100644 --- a/week-2/2-mandatory/1-fix-functions.js +++ b/week-2/2-mandatory/1-fix-functions.js @@ -4,7 +4,7 @@ function mood() { let isHappy = true; - if (isHappy) { + if (isHappy === 1) { return "I am happy"; } else { return "I am not happy"; @@ -15,7 +15,7 @@ function greaterThan10() { let num = 10; let isBigEnough; - if (isBigEnough) { + if (num >= 10) { return "num is greater than or equal to 10"; } else { return "num is not big enough"; From 239d6e116384f2e22b3718498acd625c40f195f3 Mon Sep 17 00:00:00 2001 From: osagiestar Date: Thu, 25 Jun 2020 05:31:03 +0100 Subject: [PATCH 52/84] learnt functions like slice, splice, sort(), join() --- week-2/2-mandatory/1-fix-functions.js | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/week-2/2-mandatory/1-fix-functions.js b/week-2/2-mandatory/1-fix-functions.js index 23adcf3..f2ef15a 100644 --- a/week-2/2-mandatory/1-fix-functions.js +++ b/week-2/2-mandatory/1-fix-functions.js @@ -24,22 +24,19 @@ function greaterThan10() { function sortArray() { let letters = ["a", "n", "c", "e", "z", "f"]; - let sortedLetters; - - return sortedLetters; + sorted = letters.sort().join(""); + return sorted; } function first5() { let numbers = [1, 2, 3, 4, 5, 6, 7, 8]; - let sliced; - + let sliced = numbers.slice(0, 5); return sliced; } function get3rdIndex(arr) { - let index = 3; - let element; - + // let index = 3; + let element = arr[3]; return element; } From 4ba5c4264ddcf69eab799be206f62575b8571af9 Mon Sep 17 00:00:00 2001 From: osagiestar Date: Thu, 25 Jun 2020 12:35:37 +0100 Subject: [PATCH 53/84] still working on the remaining questions --- week-2/2-mandatory/2-function-creation.js | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/week-2/2-mandatory/2-function-creation.js b/week-2/2-mandatory/2-function-creation.js index 4c3e177..9a09a4f 100644 --- a/week-2/2-mandatory/2-function-creation.js +++ b/week-2/2-mandatory/2-function-creation.js @@ -27,7 +27,12 @@ Complete the function to check if the variable `num` satisfies the following req Tip: use logical operators */ -function validate(num) {} +function validate(num) { + if ((num = "number")) { + return true; + } + return false; +} /* Write a function that removes an element from an array @@ -49,9 +54,7 @@ Write a function that: - numbers greater 100 must be replaced with 100 */ -function formatPercentage(arr) { - -} +function formatPercentage(arr) {} /* ======= TESTS - DO NOT MODIFY ===== */ @@ -84,7 +87,7 @@ test( "daniel", "irina", "gordon", - "ashleigh" + "ashleigh", ]) ); test( @@ -113,7 +116,7 @@ test( "c", "d", "e", - "f" + "f", ]) ); @@ -123,6 +126,6 @@ test( "23%", "18%", "100%", - "0.37%" + "0.37%", ]) -); \ No newline at end of file +); From f2d271b111ba9ce097bfc39ec6a6a93844165240 Mon Sep 17 00:00:00 2001 From: Osagie Okoedo Date: Thu, 25 Jun 2020 13:49:23 +0100 Subject: [PATCH 54/84] last two questions to be attempted --- week-2/2-mandatory/2-function-creation.js | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/week-2/2-mandatory/2-function-creation.js b/week-2/2-mandatory/2-function-creation.js index 9a09a4f..69a8f40 100644 --- a/week-2/2-mandatory/2-function-creation.js +++ b/week-2/2-mandatory/2-function-creation.js @@ -18,7 +18,9 @@ function tidyUpString(strArr) { return strArr; } -//trim(), toLowerCase() and replace("/", "") +// used trim(), toLowerCase() and replace("/", "") + + /* Complete the function to check if the variable `num` satisfies the following requirements: - is a number @@ -28,7 +30,7 @@ Tip: use logical operators */ function validate(num) { - if ((num = "number")) { + if ((typeof (num) === "number" && num % 2 == 0 && num <= 100)) { return true; } return false; @@ -43,6 +45,7 @@ The function must: */ function remove(arr, index) { + return; // complete this statement } From 998d1a17cd980eec8e0b2a0e688aae125d7d48a3 Mon Sep 17 00:00:00 2001 From: Osagie Okoedo Date: Thu, 25 Jun 2020 22:22:10 +0100 Subject: [PATCH 55/84] one more task to complete --- week-2/2-mandatory/2-function-creation.js | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/week-2/2-mandatory/2-function-creation.js b/week-2/2-mandatory/2-function-creation.js index 69a8f40..b973203 100644 --- a/week-2/2-mandatory/2-function-creation.js +++ b/week-2/2-mandatory/2-function-creation.js @@ -44,11 +44,14 @@ The function must: - remove the item at the specified index */ -function remove(arr, index) { - - return; // complete this statement +function remove(arr, index){ + arr.splice(index, 1); + return arr; } +// console.log(`remove element from index ${index} of array ${arr}`); +// console.log(remove(arr, index)); + /* Write a function that: - takes an array of numbers as input @@ -57,7 +60,15 @@ Write a function that: - numbers greater 100 must be replaced with 100 */ -function formatPercentage(arr) {} +function takesArray(arr) { + if (typeof(num) === "number" && Math.float(num) && num > 100) { + return true; + } +} + +// function formatPercentage(arr) { +// let num = +// // return arr.toString() /* ======= TESTS - DO NOT MODIFY ===== */ From 9f821e877a6bf4a586d9b088a382fab939059081 Mon Sep 17 00:00:00 2001 From: osagiestar Date: Fri, 26 Jun 2020 12:23:44 +0100 Subject: [PATCH 56/84] still working on task --- week-2/2-mandatory/2-function-creation.js | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/week-2/2-mandatory/2-function-creation.js b/week-2/2-mandatory/2-function-creation.js index b973203..31b398a 100644 --- a/week-2/2-mandatory/2-function-creation.js +++ b/week-2/2-mandatory/2-function-creation.js @@ -20,7 +20,6 @@ function tidyUpString(strArr) { // used trim(), toLowerCase() and replace("/", "") - /* Complete the function to check if the variable `num` satisfies the following requirements: - is a number @@ -30,7 +29,7 @@ Tip: use logical operators */ function validate(num) { - if ((typeof (num) === "number" && num % 2 == 0 && num <= 100)) { + if (typeof num === "number" && num % 2 == 0 && num <= 100) { return true; } return false; @@ -44,14 +43,11 @@ The function must: - remove the item at the specified index */ -function remove(arr, index){ +function remove(arr, index) { arr.splice(index, 1); return arr; } -// console.log(`remove element from index ${index} of array ${arr}`); -// console.log(remove(arr, index)); - /* Write a function that: - takes an array of numbers as input @@ -61,12 +57,16 @@ Write a function that: */ function takesArray(arr) { - if (typeof(num) === "number" && Math.float(num) && num > 100) { - return true; + let numArray = [2, 3, 6, 8]; + newNum = Math.floor(numArray, 2); + if(numArray > 100) { + num = 100; } } -// function formatPercentage(arr) { +// arrString = numArray.toString(); + +function formatPercentage(arr) { // let num = // // return arr.toString() From d6968eaf8ff95e1837fb8b80acb43f68d302aea9 Mon Sep 17 00:00:00 2001 From: Osagie Okoedo Date: Sun, 28 Jun 2020 07:10:59 +0100 Subject: [PATCH 57/84] learnt how to debug and used console.log() to perform checks --- week-2/2-mandatory/2-function-creation.js | 17 ++++++++----- week-2/2-mandatory/3-playing-computer.js | 31 +++++++++++++---------- week-2/2-mandatory/4-sorting-algorithm.js | 4 ++- 3 files changed, 31 insertions(+), 21 deletions(-) diff --git a/week-2/2-mandatory/2-function-creation.js b/week-2/2-mandatory/2-function-creation.js index 31b398a..46cd58a 100644 --- a/week-2/2-mandatory/2-function-creation.js +++ b/week-2/2-mandatory/2-function-creation.js @@ -56,17 +56,22 @@ Write a function that: - numbers greater 100 must be replaced with 100 */ -function takesArray(arr) { - let numArray = [2, 3, 6, 8]; - newNum = Math.floor(numArray, 2); - if(numArray > 100) { - num = 100; +function formatPercentage(arr) { + let numArray = []; + // newNum = Math.floor(numArray, 2); + for (let i = 0; i < arr.length; i++) { + if(numArray[i] > 100) { + numArray[i] = 100; + } + return numArray.toFixed(2); } + output = num.toFixed(2); +console.log(output); } + // arrString = numArray.toString(); -function formatPercentage(arr) { // let num = // // return arr.toString() diff --git a/week-2/2-mandatory/3-playing-computer.js b/week-2/2-mandatory/3-playing-computer.js index 0fa7c04..14e02af 100644 --- a/week-2/2-mandatory/3-playing-computer.js +++ b/week-2/2-mandatory/3-playing-computer.js @@ -1,42 +1,45 @@ /* You have to predict the output of this program WITHOUT EXECUTING IT. - In order to do this, try writing down the value that all variables take during each step of the program execution. - Answer the following questions: - - 1. This program throws an error. Why? (If you can't find it, try executing it). - 2. Remove the line that throws the error. - 3. What is printed to the console? - 4. How many times is "f1" called? - 5. How many times is "f2" called? - 6. What value does the "a" parameter take in the first "f1" call? + 1. This program throws an error. Why? (If you can't find it, try executing it). [ANS: ReferenceError: b is not defined. Thus, I have commented it out ] + 2. Remove the line that throws the error. [ANS: Removed line 28 {console.log(b)] + 3. What is printed to the console? [ANS: 2 and 6 were printed. Also ReferenceError: b is not defined] + 4. How many times is "f1" called? [ANS: 10, f1 is on line 38. I have used console.log("search", a) on line 41 to check how many times f1 was called] + 5. How many times is "f2" called? [ANS: 2, on line 37] + 6. What value does the "a" parameter take in the first "f1" call? [ANS: 9, I determine this by using console.log("before", a) on line 32] 7. What is the value of the "a" outer variable when "f1" is called for the first time? */ let x = 2; let a = 6; -const f1 = function(a, b) { +const f1 = function (a, b) { return a + b; }; -const f2 = function(a, b) { +const f2 = function (a, b) { return a + b + x; }; console.log(x); console.log(a); -console.log(b); +// console.log(b); [Ans 1 and Ans 2: this line has returned an error because b is not defined, thus, I have commented it out] for (let i = 0; i < 5; ++i) { + console.log(a); + // console.log("before", a) // [ANS 9: I used this line to check the value of a when f1 is called] a = a + 1; + // console.log("after", a) // [I used this line to check the value of a after] if (i % 2 === 0) { const d = f2(i, x); + //console.log("scan", x); // ANS: 2, I used this line to check how many times times f2 was called// console.log(d); } else { - const e = f1(i, a); + const e = f1(i, a); + //console.log("search", a) // [ANS: 10 times: I run this line of code to determine the number of times a was called.]// console.log(e); + } -} +} \ No newline at end of file diff --git a/week-2/2-mandatory/4-sorting-algorithm.js b/week-2/2-mandatory/4-sorting-algorithm.js index 3603942..7ea011f 100644 --- a/week-2/2-mandatory/4-sorting-algorithm.js +++ b/week-2/2-mandatory/4-sorting-algorithm.js @@ -14,7 +14,9 @@ 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) { + +} /* ======= TESTS - DO NOT MODIFY ===== */ From a1a4eb9f74ad657827de21fd9f359ef791b90523 Mon Sep 17 00:00:00 2001 From: Osagie Okoedo Date: Sun, 28 Jun 2020 08:43:35 +0100 Subject: [PATCH 58/84] learnt how to debug and used console.log() to perform checks --- week-2/2-mandatory/2-function-creation.js | 13 +++++++++---- week-2/2-mandatory/3-playing-computer.js | 6 +++--- 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/week-2/2-mandatory/2-function-creation.js b/week-2/2-mandatory/2-function-creation.js index 46cd58a..bbc0ed9 100644 --- a/week-2/2-mandatory/2-function-creation.js +++ b/week-2/2-mandatory/2-function-creation.js @@ -57,15 +57,20 @@ Write a function that: */ function formatPercentage(arr) { - let numArray = []; + let numArray; + let roundedNum; + let strArray; // newNum = Math.floor(numArray, 2); for (let i = 0; i < arr.length; i++) { - if(numArray[i] > 100) { + if (numArray[i] > 100) { numArray[i] = 100; } - return numArray.toFixed(2); + roundedNum = Math.floor(2); + + } + return numArray[i].toFixed(2); } - output = num.toFixed(2); + output = numArray.toFixed(2); console.log(output); } diff --git a/week-2/2-mandatory/3-playing-computer.js b/week-2/2-mandatory/3-playing-computer.js index 14e02af..a43c309 100644 --- a/week-2/2-mandatory/3-playing-computer.js +++ b/week-2/2-mandatory/3-playing-computer.js @@ -5,8 +5,8 @@ Answer the following questions: 1. This program throws an error. Why? (If you can't find it, try executing it). [ANS: ReferenceError: b is not defined. Thus, I have commented it out ] 2. Remove the line that throws the error. [ANS: Removed line 28 {console.log(b)] - 3. What is printed to the console? [ANS: 2 and 6 were printed. Also ReferenceError: b is not defined] - 4. How many times is "f1" called? [ANS: 10, f1 is on line 38. I have used console.log("search", a) on line 41 to check how many times f1 was called] + 3. What is printed to the console? [ANS: 2, 6, 6, 4, 7, 9, 8, 6, 9, 13, 10, 8] + 4. How many times is "f1" called? [ANS: 10, f1 is on line 40. I have used console.log("search", a) on line 41 to check how many times f1 was called] 5. How many times is "f2" called? [ANS: 2, on line 37] 6. What value does the "a" parameter take in the first "f1" call? [ANS: 9, I determine this by using console.log("before", a) on line 32] 7. What is the value of the "a" outer variable when "f1" is called for the first time? @@ -25,7 +25,7 @@ const f2 = function (a, b) { console.log(x); console.log(a); -// console.log(b); [Ans 1 and Ans 2: this line has returned an error because b is not defined, thus, I have commented it out] +// console.log(b); //[Ans 1 and Ans 2: this line has returned an error because b is not defined, thus, I have commented it out] for (let i = 0; i < 5; ++i) { console.log(a); From 2b0331eadb873907e8cdeb66bc13824fb6991925 Mon Sep 17 00:00:00 2001 From: Osagie Okoedo Date: Mon, 29 Jun 2020 08:51:12 +0100 Subject: [PATCH 59/84] learnt to parseFloat method --- week-2/2-mandatory/2-function-creation.js | 24 ++++++------------ week-2/2-mandatory/4-sorting-algorithm.js | 30 +++++++++++++++++++++-- 2 files changed, 36 insertions(+), 18 deletions(-) diff --git a/week-2/2-mandatory/2-function-creation.js b/week-2/2-mandatory/2-function-creation.js index bbc0ed9..383838b 100644 --- a/week-2/2-mandatory/2-function-creation.js +++ b/week-2/2-mandatory/2-function-creation.js @@ -57,29 +57,21 @@ Write a function that: */ function formatPercentage(arr) { - let numArray; - let roundedNum; - let strArray; - // newNum = Math.floor(numArray, 2); + for (let i = 0; i < arr.length; i++) { - if (numArray[i] > 100) { - numArray[i] = 100; + if (arr[i] > 100) { + arr[i] = "100%"; // gives any number above 100 a value of "100%" } - roundedNum = Math.floor(2); - + else { + arr[i] = `${parseFloat(arr[i].toFixed(2))}%`; + // arr[i] = Math.round((arr[i] + Number.EPSILON) * 100) / 100 + "%" [alternative method]// } - return numArray[i].toFixed(2); } - output = numArray.toFixed(2); -console.log(output); + return arr; } + -// arrString = numArray.toString(); - -// let num = -// // return arr.toString() - /* ======= TESTS - DO NOT MODIFY ===== */ function arraysEqual(a, b) { diff --git a/week-2/2-mandatory/4-sorting-algorithm.js b/week-2/2-mandatory/4-sorting-algorithm.js index 7ea011f..ffefc2a 100644 --- a/week-2/2-mandatory/4-sorting-algorithm.js +++ b/week-2/2-mandatory/4-sorting-algorithm.js @@ -15,8 +15,34 @@ You don't have to worry about making this algorithm work fast! The idea is to ge */ function sortAges(arr) { - -} + let result = []; + for (let age = 0; age < agesCase2.length; age++) { + if (typeof agesCase2[age] === "number") { + result.push(agesCase2[age]); // filters only numbers and adds to the empty array (result)// + } + } + return result; +} + // console.log(result); + function sorting(a, b) { + return a - b + } + +return result.sort(sorting); + + + +// let removeNonNumber = []; +// let sortAscending = []; +// for (let i = 0; i < sortAges.length; i++) { +// if (typeof arr[i] === "number") { +// removeNonNumber.push(arr[i]); +// } +// } +// sortAscending = function (a, b) { +// return a - b; +// } +// } /* ======= TESTS - DO NOT MODIFY ===== */ From a151e32fe5a8fed114d092e05acde908aa061061 Mon Sep 17 00:00:00 2001 From: Osagie Okoedo Date: Mon, 29 Jun 2020 09:29:21 +0100 Subject: [PATCH 60/84] tested on repl.it but not passing --- week-2/2-mandatory/4-sorting-algorithm.js | 23 ++++++----------------- 1 file changed, 6 insertions(+), 17 deletions(-) diff --git a/week-2/2-mandatory/4-sorting-algorithm.js b/week-2/2-mandatory/4-sorting-algorithm.js index ffefc2a..98b3ce7 100644 --- a/week-2/2-mandatory/4-sorting-algorithm.js +++ b/week-2/2-mandatory/4-sorting-algorithm.js @@ -16,33 +16,22 @@ You don't have to worry about making this algorithm work fast! The idea is to ge function sortAges(arr) { let result = []; - for (let age = 0; age < agesCase2.length; age++) { - if (typeof agesCase2[age] === "number") { - result.push(agesCase2[age]); // filters only numbers and adds to the empty array (result)// + for (let age = 0; age < arr.length; age++) { + if (typeof arr[age] === "number") { + result.push(arr[age]); // filters only numbers and adds to the empty array (result)// } } return result; } // console.log(result); - function sorting(a, b) { - return a - b + function sorting(a, b) { + return a - b } -return result.sort(sorting); +return result.sort(sorting); // sorts numbers in ascending order// -// let removeNonNumber = []; -// let sortAscending = []; -// for (let i = 0; i < sortAges.length; i++) { -// if (typeof arr[i] === "number") { -// removeNonNumber.push(arr[i]); -// } -// } -// sortAscending = function (a, b) { -// return a - b; -// } -// } /* ======= TESTS - DO NOT MODIFY ===== */ From 0aeb8e73f3e47d392b735d2b83a4bcd2017f32e7 Mon Sep 17 00:00:00 2001 From: Osagie Okoedo Date: Mon, 29 Jun 2020 16:57:50 +0100 Subject: [PATCH 61/84] applied push method and added return which I missed before --- week-2/2-mandatory/4-sorting-algorithm.js | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/week-2/2-mandatory/4-sorting-algorithm.js b/week-2/2-mandatory/4-sorting-algorithm.js index 98b3ce7..799f96e 100644 --- a/week-2/2-mandatory/4-sorting-algorithm.js +++ b/week-2/2-mandatory/4-sorting-algorithm.js @@ -21,14 +21,13 @@ function sortAges(arr) { result.push(arr[age]); // filters only numbers and adds to the empty array (result)// } } - return result; + function sorting(a, b) { + return a - b; } - // console.log(result); - function sorting(a, b) { - return a - b - } + return sortAscending = result.sort(sorting); // sorts numbers in ascending order// +} -return result.sort(sorting); // sorts numbers in ascending order// + From 3b5557556ca427d7ac07c33cbe5b035c2e9bcdef Mon Sep 17 00:00:00 2001 From: Osagie Okoedo Date: Wed, 1 Jul 2020 14:47:28 +0100 Subject: [PATCH 62/84] applied filter method and used arrow method --- week-3/2-mandatory/1-oxygen-levels.js | 12 +++++++++++- week-3/2-mandatory/2-bush-berries.js | 20 ++++++++++++++++++-- 2 files changed, 29 insertions(+), 3 deletions(-) diff --git a/week-3/2-mandatory/1-oxygen-levels.js b/week-3/2-mandatory/1-oxygen-levels.js index 3c02135..aa85343 100644 --- a/week-3/2-mandatory/1-oxygen-levels.js +++ b/week-3/2-mandatory/1-oxygen-levels.js @@ -10,8 +10,18 @@ Write a function that finds the oxygen level of the first safe planet - Oxygen b */ function safeLevels() { - + const convert = arr.map(function (level) { + return (parseFloat(level)) + }) + const safeLevels = convert.filter(function (n) { + return n > 19.5 && n < 23.5 + }) + return `"${safeLevels[0]}%"` } +// let output = `"${safeLevels[0]}%"` +// console.log(output) + + /* ======= TESTS - DO NOT MODIFY ===== */ diff --git a/week-3/2-mandatory/2-bush-berries.js b/week-3/2-mandatory/2-bush-berries.js index d900323..cefbd01 100644 --- a/week-3/2-mandatory/2-bush-berries.js +++ b/week-3/2-mandatory/2-bush-berries.js @@ -10,10 +10,26 @@ Use the tests to confirm which message to return */ -function bushChecker() { - +function bushChecker(bush) { + if (bush.filter(color => color !== "pink").length > 0) { + return "Toxic! Leave bush alone!" + } +else +return "Bush is safe to eat from" } +// function isNotPink(color) { +// return color !== "pink"; +// } + +// function bushChecker(bush) { +// if (bush.filter(isNotPink).length > 0) { +// return "Toxic! Leave bush alone!" +// } +// else +// return "Bush is safe to eat from" +// } + /* ======= TESTS - DO NOT MODIFY ===== */ let bushBerryColours1 = ["pink", "pink", "pink", "neon", "pink", "transparent"] From 03eb52b893b71a4143e6fc25658b3a352fbc156a Mon Sep 17 00:00:00 2001 From: Osagie Okoedo Date: Wed, 1 Jul 2020 17:10:24 +0100 Subject: [PATCH 63/84] learnt map method and used parseFloat --- week-3/2-mandatory/1-oxygen-levels.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/week-3/2-mandatory/1-oxygen-levels.js b/week-3/2-mandatory/1-oxygen-levels.js index aa85343..1ca6d51 100644 --- a/week-3/2-mandatory/1-oxygen-levels.js +++ b/week-3/2-mandatory/1-oxygen-levels.js @@ -9,14 +9,14 @@ 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) { const convert = arr.map(function (level) { return (parseFloat(level)) }) const safeLevels = convert.filter(function (n) { return n > 19.5 && n < 23.5 }) - return `"${safeLevels[0]}%"` + return `${safeLevels[0]}%` } // let output = `"${safeLevels[0]}%"` // console.log(output) From e3dd10d7194d3f5494a9e46669c6c630c3c1ed04 Mon Sep 17 00:00:00 2001 From: Osagie Okoedo Date: Thu, 2 Jul 2020 03:12:05 +0100 Subject: [PATCH 64/84] applied the find method --- week-3/1-exercises/A-array-find/exercise.js | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/week-3/1-exercises/A-array-find/exercise.js b/week-3/1-exercises/A-array-find/exercise.js index d7fd51f..3a09018 100644 --- a/week-3/1-exercises/A-array-find/exercise.js +++ b/week-3/1-exercises/A-array-find/exercise.js @@ -7,9 +7,16 @@ var names = ["Rakesh", "Antonio", "Alexandra", "Andronicus", "Annam", "Mikey", "Anastasia", "Karim", "Ahmed"]; -var longNameThatStartsWithA = findLongNameThatStartsWithA(names); +function isLongNameStart(name) { + for (let i = 0; i < name.length; i++) { + return (name.length > 7 && name[i][0] === "A") + } +} + +var longNameThatStartsWithA = names.find(isLongNameStart); console.log(longNameThatStartsWithA); + /* EXPECTED OUTPUT */ // "Alexandra" From 412cd9f200a13b9ec0a622d4fcc6aac6fd417202 Mon Sep 17 00:00:00 2001 From: Osagie Okoedo Date: Thu, 2 Jul 2020 04:12:53 +0100 Subject: [PATCH 65/84] applied the process.exit(1) for termination of execution --- week-3/1-exercises/B-array-some/exercise.js | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/week-3/1-exercises/B-array-some/exercise.js b/week-3/1-exercises/B-array-some/exercise.js index 965c052..d05c19e 100644 --- a/week-3/1-exercises/B-array-some/exercise.js +++ b/week-3/1-exercises/B-array-some/exercise.js @@ -8,6 +8,21 @@ var pairsByIndex = [[0, 3], [1, 2], [2, 1], null, [3, 0]]; +var pairs = pairsByIndex.map(function (indexes) { + + const nullCheck = (element) => element === null; + + if (pairsByIndex.some(nullCheck) === true) { + process.exit(1); + } + else { + return [student, mentor]; + } +}) + console.log(pairs) + + + // 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); @@ -15,7 +30,7 @@ var pairsByIndex = [[0, 3], [1, 2], [2, 1], null, [3, 0]]; var students = ["Islam", "Lesley", "Harun", "Rukmini"]; var mentors = ["Daniel", "Irina", "Mozafar", "Luke"]; -var pairs = pairsByIndex.map(function(indexes) { +var pairs = pairsByIndex.map(function (indexes) { var student = students[indexes[0]]; var mentor = mentors[indexes[1]]; return [student, mentor]; From 5fdf9915456f409a942a2add63043c44b6fb49f5 Mon Sep 17 00:00:00 2001 From: Osagie Okoedo Date: Thu, 2 Jul 2020 04:53:23 +0100 Subject: [PATCH 66/84] Updated the task --- week-3/2-mandatory/1-oxygen-levels.js | 46 +++++++++++++-------------- 1 file changed, 22 insertions(+), 24 deletions(-) diff --git a/week-3/2-mandatory/1-oxygen-levels.js b/week-3/2-mandatory/1-oxygen-levels.js index 1ca6d51..4e1f6a0 100644 --- a/week-3/2-mandatory/1-oxygen-levels.js +++ b/week-3/2-mandatory/1-oxygen-levels.js @@ -10,41 +10,39 @@ Write a function that finds the oxygen level of the first safe planet - Oxygen b */ function safeLevels(arr) { - const convert = arr.map(function (level) { - return (parseFloat(level)) - }) - const safeLevels = convert.filter(function (n) { - return n > 19.5 && n < 23.5 - }) - return `${safeLevels[0]}%` + const convert = arr.map(function (level) { + return parseFloat(level); + }); + const safeLevels = convert.filter(function (n) { + return n > 19.5 && n < 23.5; + }); + return `${safeLevels[0]}%`; } // let output = `"${safeLevels[0]}%"` // console.log(output) - - /* ======= 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%" + "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 + "safeLevels function works - case 2", + safeLevels(oxygenLevels2) === "20.2%" +); From 54288e744e453fbdf03d06145ff13a8fe4ce3632 Mon Sep 17 00:00:00 2001 From: Osagie Okoedo Date: Thu, 2 Jul 2020 05:43:09 +0100 Subject: [PATCH 67/84] updated the file/task --- week-3/2-mandatory/1-oxygen-levels.js | 23 +++++++++++++++++------ 1 file changed, 17 insertions(+), 6 deletions(-) diff --git a/week-3/2-mandatory/1-oxygen-levels.js b/week-3/2-mandatory/1-oxygen-levels.js index 4e1f6a0..51c8580 100644 --- a/week-3/2-mandatory/1-oxygen-levels.js +++ b/week-3/2-mandatory/1-oxygen-levels.js @@ -25,24 +25,35 @@ function safeLevels(arr) { 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 oxygenLevels3 = ["200%", "21.1%"]; -function test(test_name, expr) { +const util = require('util'); + +function test(test_name, actual, expected) { let status; - if (expr) { + if (actual === expected) { status = "PASSED"; } else { - status = "FAILED"; + status = `FAILED: expected: ${util.inspect(expected)} but your function returned: ${util.inspect(actual)}`; } console.log(`${test_name}: ${status}`); } test( - "safeLevels function works - case 2", - safeLevels(oxygenLevels1) === "19.9%" + "safeLevels function works - case 1", + safeLevels(oxygenLevels1), + "19.9%" ); test( "safeLevels function works - case 2", - safeLevels(oxygenLevels2) === "20.2%" + safeLevels(oxygenLevels2), + "20.2%" +); + +test( + "safeLevels function works - case 3", + safeLevels(oxygenLevels3), + "21.1%" ); From 0751024910caba88488c4976c27531459bf86bd8 Mon Sep 17 00:00:00 2001 From: Osagie Okoedo Date: Fri, 3 Jul 2020 16:11:42 +0100 Subject: [PATCH 68/84] applied split and filter methods --- week-3/2-mandatory/3-space-colonies.js | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/week-3/2-mandatory/3-space-colonies.js b/week-3/2-mandatory/3-space-colonies.js index f99891a..c415d3d 100644 --- a/week-3/2-mandatory/3-space-colonies.js +++ b/week-3/2-mandatory/3-space-colonies.js @@ -1,3 +1,4 @@ + /* 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, @@ -8,10 +9,18 @@ NOTE: don't include any element that is not a "family". */ -function colonisers() { - +function landedFamily(element) { + if (element.split(" ")[1] === "family") { + return element[0] === "A"; + } } +function colonisers(voyagers) { + + return voyagers.filter(landedFamily); +}; + + /* ======= TESTS - DO NOT MODIFY ===== */ const voyagers = [ From 833a6a5e7b71db6c3dff74407117c281b906177e Mon Sep 17 00:00:00 2001 From: osagiestar Date: Sun, 5 Jul 2020 14:33:12 +0100 Subject: [PATCH 69/84] filter and map methods used --- week-3/2-mandatory/4-eligible-students.js | 62 +++++++++++++---------- 1 file changed, 36 insertions(+), 26 deletions(-) diff --git a/week-3/2-mandatory/4-eligible-students.js b/week-3/2-mandatory/4-eligible-students.js index 6424b01..e741d27 100644 --- a/week-3/2-mandatory/4-eligible-students.js +++ b/week-3/2-mandatory/4-eligible-students.js @@ -7,8 +7,14 @@ - Returns an array containing only the names of the who have attended AT LEAST 8 classes */ -function eligibleStudents() { - +function eligibleStudents(arr) { + let attended8Classes = arr.filter(function (name) { + return name[1] >= 8; + }); + let namesOfAttended8 = attended8Classes.map(function (names) { + return names[0]; + }); + return namesOfAttended8; } /* ======= TESTS - DO NOT MODIFY ===== */ @@ -19,34 +25,38 @@ const attendances = [ ["Elamin", 6], ["Adam", 7], ["Tayoa", 11], - ["Nina", 10] -] + ["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 2ceca37383f29e0e15a1e340e5b7c27a62b720b6 Mon Sep 17 00:00:00 2001 From: osagiestar Date: Mon, 6 Jul 2020 15:47:37 +0100 Subject: [PATCH 70/84] applied includes() method --- week-3/2-mandatory/6-lane-names.js | 62 ++++++++++++++++-------------- 1 file changed, 33 insertions(+), 29 deletions(-) diff --git a/week-3/2-mandatory/6-lane-names.js b/week-3/2-mandatory/6-lane-names.js index eddfe44..05dfc45 100644 --- a/week-3/2-mandatory/6-lane-names.js +++ b/week-3/2-mandatory/6-lane-names.js @@ -4,43 +4,47 @@ Write a function that will return all street names which contain 'Lane' in their name. */ -function getLanes() { - +function getLanes(streetName) { + let streetNameLane = streetName.filter(function (laneName) { + return laneName.includes("Lane"); + }); + return streetNameLane; } /* ======= TESTS - DO NOT MODIFY ===== */ const streetNames = [ - "Abchurch Lane", - "Adam's Court", - "Addle Hill", - "Addle Lane", - "Alban Highwalk" -] + "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 2b3f4a36ad4fbe03d34f5b5dca3ee0482aed8e10 Mon Sep 17 00:00:00 2001 From: osagiestar Date: Mon, 6 Jul 2020 16:01:10 +0100 Subject: [PATCH 71/84] applied includes() method with filter and map methods --- week-3/2-mandatory/5-journey-planner.js | 71 ++++++++++++++----------- 1 file changed, 41 insertions(+), 30 deletions(-) diff --git a/week-3/2-mandatory/5-journey-planner.js b/week-3/2-mandatory/5-journey-planner.js index 53499c3..63aa11f 100644 --- a/week-3/2-mandatory/5-journey-planner.js +++ b/week-3/2-mandatory/5-journey-planner.js @@ -7,8 +7,14 @@ NOTE: only the names should be returned, not the means of transport. */ -function journeyPlanner() { - +function journeyPlanner(londonLocations, transportMode) { + const transportLoc = londonLocations.filter(function (transport) { + return transport.includes(transportMode); + }); + const locationName = transportLoc.map(function (location) { + return location[0]; + }); + return locationName; } /* ======= TESTS - DO NOT MODIFY ===== */ @@ -17,8 +23,8 @@ const londonLocations = [ ["Angel", "tube", "bus"], ["London Bridge", "tube", "river boat"], ["Tower Bridge", "tube", "bus"], - ["Greenwich", "bus", "river boat"] -] + ["Greenwich", "bus", "river boat"], +]; function arraysEqual(a, b) { if (a === b) return true; @@ -33,33 +39,38 @@ function arraysEqual(a, b) { } 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 c73816bb28de1a99a5c2a9b3b3fb69f8dac842ab Mon Sep 17 00:00:00 2001 From: osagiestar Date: Mon, 6 Jul 2020 16:43:28 +0100 Subject: [PATCH 72/84] need to practice RegEx more --- week-3/2-mandatory/7-password-validator.js | 76 ++++++++++++---------- 1 file changed, 43 insertions(+), 33 deletions(-) diff --git a/week-3/2-mandatory/7-password-validator.js b/week-3/2-mandatory/7-password-validator.js index 57b3d53..749e36b 100644 --- a/week-3/2-mandatory/7-password-validator.js +++ b/week-3/2-mandatory/7-password-validator.js @@ -10,7 +10,7 @@ Passwords must - Have English uppercase letters (A-Z) - Have English lowercase letters (a-z) - Have numbers (0-9) -- Have non-alphanumeric symbols ("!", "#", "$", "%", ".") +- Have non-alphanumeric symbols ("!", "#", "$", "%", ".", "*", "&") Passwords must not be any previous password in the passwords array. @@ -23,47 +23,57 @@ PasswordValidationResult= [false, false, false, false, true] */ function validatePasswords(passwords) { - + let checkPasswords = passwords.map((pass, index, array) => { + if ( + pass.length >= 5 && + /[A-Z]/.test(pass) && + /[a-z]/.test(pass) && + /[0-9]/.test(pass) && + /[!#$%.*&]/.test(pass) && + array.indexOf(pass) === index + ) { + return true; + } else { + return false; + } + }); + return checkPasswords; } /* ======= 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 734d489461c3aeda4969e6c91ec1aa2432575cc0 Mon Sep 17 00:00:00 2001 From: osagiestar Date: Mon, 6 Jul 2020 21:44:50 +0100 Subject: [PATCH 73/84] cleaned up code --- week-3/2-mandatory/1-oxygen-levels.js | 30 ++++++++------------------- 1 file changed, 9 insertions(+), 21 deletions(-) diff --git a/week-3/2-mandatory/1-oxygen-levels.js b/week-3/2-mandatory/1-oxygen-levels.js index 51c8580..dd66056 100644 --- a/week-3/2-mandatory/1-oxygen-levels.js +++ b/week-3/2-mandatory/1-oxygen-levels.js @@ -18,8 +18,6 @@ function safeLevels(arr) { }); return `${safeLevels[0]}%`; } -// let output = `"${safeLevels[0]}%"` -// console.log(output) /* ======= TESTS - DO NOT MODIFY ===== */ @@ -27,33 +25,23 @@ 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 oxygenLevels3 = ["200%", "21.1%"]; -const util = require('util'); +const util = require("util"); function test(test_name, actual, expected) { let status; if (actual === expected) { status = "PASSED"; } else { - status = `FAILED: expected: ${util.inspect(expected)} but your function returned: ${util.inspect(actual)}`; + status = `FAILED: expected: ${util.inspect( + expected + )} but your function returned: ${util.inspect(actual)}`; } console.log(`${test_name}: ${status}`); } -test( - "safeLevels function works - case 1", - safeLevels(oxygenLevels1), - "19.9%" -); - -test( - "safeLevels function works - case 2", - safeLevels(oxygenLevels2), - "20.2%" -); - -test( - "safeLevels function works - case 3", - safeLevels(oxygenLevels3), - "21.1%" -); +test("safeLevels function works - case 1", safeLevels(oxygenLevels1), "19.9%"); + +test("safeLevels function works - case 2", safeLevels(oxygenLevels2), "20.2%"); + +test("safeLevels function works - case 3", safeLevels(oxygenLevels3), "21.1%"); From eb9c5232a5b6a55850ee124301cf1e3d6308a47e Mon Sep 17 00:00:00 2001 From: osagiestar Date: Mon, 6 Jul 2020 23:39:23 +0100 Subject: [PATCH 74/84] still working on it --- week-3/1-exercises/D-array-filter/exercise.js | 9 +++++++-- 1 file changed, 7 insertions(+), 2 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..97d001e 100644 --- a/week-3/1-exercises/D-array-filter/exercise.js +++ b/week-3/1-exercises/D-array-filter/exercise.js @@ -8,12 +8,17 @@ var pairsByIndexRaw = [[0, 3], [1, 2], [2, 1], null, [1], false, "whoops"]; -var pairsByIndex; // Complete this statement +function isAnArray(Array) { + return Array.isArray([]); +} + +var pairsByIndex = pairsByIndexRaw.filter(isAnArray); +// Complete this statement var students = ["Islam", "Lesley", "Harun", "Rukmini"]; var mentors = ["Daniel", "Irina", "Mozafar", "Luke"]; -var pairs = pairsByIndex.map(function(indexes) { +var pairs = pairsByIndex.map(function (indexes) { var student = students[indexes[0]]; var mentor = mentors[indexes[1]]; return [student, mentor]; From 967b433e911a068e4abb9f1733addb4bb65d89ed Mon Sep 17 00:00:00 2001 From: osagiestar Date: Wed, 8 Jul 2020 02:26:21 +0100 Subject: [PATCH 75/84] debugging after feedback --- week-1/1-exercises/K-functions-parameters/exercise.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/week-1/1-exercises/K-functions-parameters/exercise.js b/week-1/1-exercises/K-functions-parameters/exercise.js index 808c5bd..ee11221 100644 --- a/week-1/1-exercises/K-functions-parameters/exercise.js +++ b/week-1/1-exercises/K-functions-parameters/exercise.js @@ -1,7 +1,7 @@ // multiplication function// -function multiply() { - return 3 * 4; +function multiply(a, b) { + return a * b; } let result = multiply(3, 4); console.log(result); From 2983e664bd05de886cf7e4ebdb6417d6a3aadb45 Mon Sep 17 00:00:00 2001 From: osagiestar Date: Wed, 8 Jul 2020 02:29:41 +0100 Subject: [PATCH 76/84] debugging from feedback --- week-1/1-exercises/K-functions-parameters/exercise2.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/week-1/1-exercises/K-functions-parameters/exercise2.js b/week-1/1-exercises/K-functions-parameters/exercise2.js index a2ddcdd..e346262 100644 --- a/week-1/1-exercises/K-functions-parameters/exercise2.js +++ b/week-1/1-exercises/K-functions-parameters/exercise2.js @@ -1,7 +1,7 @@ // Declare your function first -function divide() { - return 3 / 4; +function divide(a, b) { + return a / b; } -let result = divide(); +let result = divide(3, 4); console.log(result); From ebfb1c300414a1e53ee151a97b39339d814bf689 Mon Sep 17 00:00:00 2001 From: osagiestar Date: Wed, 8 Jul 2020 02:39:42 +0100 Subject: [PATCH 77/84] debugging from assessor's feedback --- week-1/1-exercises/K-functions-parameters/exercise3.js | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/week-1/1-exercises/K-functions-parameters/exercise3.js b/week-1/1-exercises/K-functions-parameters/exercise3.js index ae17d21..abb24b6 100644 --- a/week-1/1-exercises/K-functions-parameters/exercise3.js +++ b/week-1/1-exercises/K-functions-parameters/exercise3.js @@ -1,8 +1,8 @@ // Write your function here -function createGreeting() { - let name = "Daniel"; - let greeting = "Hello, my name is "; - let fullGreeting = greeting + name; +function createGreeting(name) { + // let greeting = "Hello, my name is "; + // let fullGreeting = greeting + name; + let fullGreeting = "Hello, my name is " + name; return fullGreeting; } -console.log(createGreeting()); +console.log(createGreeting("Daniel")); From 7ed52af0f149bc6b84431b655952476d3d447273 Mon Sep 17 00:00:00 2001 From: osagiestar Date: Wed, 8 Jul 2020 02:56:18 +0100 Subject: [PATCH 78/84] debugging based on feedback --- .../1-exercises/K-functions-parameters/exercise4.js | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/week-1/1-exercises/K-functions-parameters/exercise4.js b/week-1/1-exercises/K-functions-parameters/exercise4.js index 6cff3ee..85eacb2 100644 --- a/week-1/1-exercises/K-functions-parameters/exercise4.js +++ b/week-1/1-exercises/K-functions-parameters/exercise4.js @@ -1,11 +1,6 @@ // Declare your function first -function sum() { - return 13 + 124; - // let num1 = 13; - // let num2 = 124; - // let addition = 13 + 124; - // return addition; +function sum(num1, num2) { + return num1 + num2; } // Call the function and assign to a variable `sum` - -console.log(sum()); +console.log(sum(13, 124)); // calling the function and passing the numbers From d5a93121122f3c769b943c80dc84d39872de1cce Mon Sep 17 00:00:00 2001 From: osagiestar Date: Wed, 8 Jul 2020 03:08:42 +0100 Subject: [PATCH 79/84] debugging codes --- week-1/1-exercises/K-functions-parameters/exercise5.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/week-1/1-exercises/K-functions-parameters/exercise5.js b/week-1/1-exercises/K-functions-parameters/exercise5.js index 0672756..7b10de8 100644 --- a/week-1/1-exercises/K-functions-parameters/exercise5.js +++ b/week-1/1-exercises/K-functions-parameters/exercise5.js @@ -1,8 +1,8 @@ // Declare your function here -function createLongGreeting() { - let name = "Daniel"; - let age = 30; +function createLongGreeting(name, age) { + // let name = "Daniel"; + // let age = 30; const greeting = `My name is ${name} and I'm ${age} years old`; return greeting; } -console.log(createLongGreeting()); +console.log(createLongGreeting("Daniel", 30)); From 1a6f7debea401908bfec07c477c419dee0af46b6 Mon Sep 17 00:00:00 2001 From: osagiestar Date: Wed, 8 Jul 2020 06:03:22 +0100 Subject: [PATCH 80/84] exercises completed and feedback implemented --- .../L-functions-nested/exercise.js | 36 +++++++++++++++---- 1 file changed, 29 insertions(+), 7 deletions(-) diff --git a/week-1/1-exercises/L-functions-nested/exercise.js b/week-1/1-exercises/L-functions-nested/exercise.js index fc89a87..89adaa1 100644 --- a/week-1/1-exercises/L-functions-nested/exercise.js +++ b/week-1/1-exercises/L-functions-nested/exercise.js @@ -2,14 +2,14 @@ function percentProgram(firstNumber, secondNumber) { let overallTotal = firstNumber + secondNumber; - let percentage = Math.floor((firstNumber / overallTotal) * 100); + let percentage = Math.round((firstNumber / overallTotal) * 100); return percentage; } function message(numberOfStudents, numberOfMentors) { let percentOfStudents = percentProgram(numberOfStudents, numberOfMentors); let percentOfMentors = percentProgram(numberOfMentors, numberOfStudents); - let fullMessage = `Percentage students: ${percentOfStudents}% and Percentage mentors: ${percentOfMentors}%`; + let fullMessage = `Percentage students: ${percentOfStudents}% Percentage mentors: ${percentOfMentors}%`; return fullMessage; } let finalMessage = message(15, 8); @@ -18,8 +18,30 @@ console.log(finalMessage); // console.log(`${comment1} ${approxPercent}%`); // console.log(`${comment2} ${approxPer}%`); -// var mentor1 = "Daniel"; -// var mentor2 = "Irina"; -// var mentor3 = "Mimi"; -// var mentor4 = "Rob"; -// var mentor5 = "Yohannes"; +var mentor1 = "Daniel"; +var mentor2 = "Irina"; +var mentor3 = "Mimi"; +var mentor4 = "Rob"; +var mentor5 = "Yohannes"; + +function shoutyGreeting(mentor) { + let nameUpperCase = mentor.toUpperCase(); + let greeting = `HELLO ${nameUpperCase}`; + return greeting; +} + +let greeting1 = shoutyGreeting(mentor1); +let greeting2 = shoutyGreeting(mentor2); +let greeting3 = shoutyGreeting(mentor3); +let greeting4 = shoutyGreeting(mentor4); +let greeting5 = shoutyGreeting(mentor5); + +console.log(greeting1); + +console.log(greeting2); + +console.log(greeting3); + +console.log(greeting4); + +console.log(greeting5); From 221a09bb11043f717aa315974022fa9c4f20b432 Mon Sep 17 00:00:00 2001 From: osagiestar Date: Wed, 8 Jul 2020 17:00:17 +0100 Subject: [PATCH 81/84] calling function method --- week-1/2-mandatory/4-tax.js | 57 ++++++++++++++++++++----------------- 1 file changed, 31 insertions(+), 26 deletions(-) diff --git a/week-1/2-mandatory/4-tax.js b/week-1/2-mandatory/4-tax.js index 82a2c81..55137bd 100644 --- a/week-1/2-mandatory/4-tax.js +++ b/week-1/2-mandatory/4-tax.js @@ -24,42 +24,47 @@ function calculateSalesTax(productPrice) { Remember that the prices must include the sales tax (hint: you already wrote a function for this!) */ -<<<<<<< HEAD -/* salesPrice is the productPrice + taxValue*/ -/* taxValue is the productPrice * salesTax*/ - -function formatCurrency(productPrice) { - let salesTax = 0.2; - let taxValue = productPrice * salesTax; - let salesPrice = productPrice + taxValue; - return `£${salesPrice.toFixed(2)}`; +function addTaxAndFormatCurrency(productPrice) { + let formattedValue = `£${calculateSalesTax(productPrice).toFixed(2)}`; + return formattedValue; } -======= -function addTaxAndFormatCurrency() {} ->>>>>>> 8d17c19782cb831f7eeeb6c2adc0555b17d81af4 /* ======= TESTS - DO NOT MODIFY ===== There are some Tests in this file that will help you work out if your code is working. To run these tests type `node 4-tax.js` into your terminal */ -const util = require('util'); +const util = require("util"); function test(test_name, actual, expected) { - let status; - if (actual === expected) { - status = "PASSED"; - } else { - status = `FAILED: expected: ${util.inspect(expected)} but your function returned: ${util.inspect(actual)}`; - } + let status; + if (actual === expected) { + status = "PASSED"; + } else { + status = `FAILED: expected: ${util.inspect( + expected + )} but your function returned: ${util.inspect(actual)}`; + } - console.log(`${test_name}: ${status}`); + console.log(`${test_name}: ${status}`); } -test("calculateSalesTax function - case 1 works", calculateSalesTax(15), 18) -test("calculateSalesTax function - case 2 works", calculateSalesTax(17.5), 21) -test("calculateSalesTax function - case 3 works", calculateSalesTax(34), 40.8) +test("calculateSalesTax function - case 1 works", calculateSalesTax(15), 18); +test("calculateSalesTax function - case 2 works", calculateSalesTax(17.5), 21); +test("calculateSalesTax function - case 3 works", calculateSalesTax(34), 40.8); -test("addTaxAndFormatCurrency function - case 1 works", addTaxAndFormatCurrency(15), "£18.00") -test("addTaxAndFormatCurrency function - case 2 works", addTaxAndFormatCurrency(17.5), "£21.00") -test("addTaxAndFormatCurrency function - case 3 works", addTaxAndFormatCurrency(34), "£40.80") +test( + "addTaxAndFormatCurrency function - case 1 works", + addTaxAndFormatCurrency(15), + "£18.00" +); +test( + "addTaxAndFormatCurrency function - case 2 works", + addTaxAndFormatCurrency(17.5), + "£21.00" +); +test( + "addTaxAndFormatCurrency function - case 3 works", + addTaxAndFormatCurrency(34), + "£40.80" +); From 8ece4b16231c4c46f5c69fdb69f9ed26659320ee Mon Sep 17 00:00:00 2001 From: osagiestar Date: Wed, 8 Jul 2020 23:08:36 +0100 Subject: [PATCH 82/84] corrected error --- week-1/3-extra/1-currency-conversion.js | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/week-1/3-extra/1-currency-conversion.js b/week-1/3-extra/1-currency-conversion.js index 4ec34f7..0730787 100644 --- a/week-1/3-extra/1-currency-conversion.js +++ b/week-1/3-extra/1-currency-conversion.js @@ -20,7 +20,7 @@ function convertToUSD(pound) { function convertToBRL(pound) { let convert = pound * 5.7; let interest = convert * 0.01; - return convert + interest; + return convert - interest; } /* ======= TESTS - DO NOT MODIFY ===== @@ -29,17 +29,19 @@ There are some Tests in this file that will help you work out if your code is wo To run these tests type `node 1-currency-conversion` into your terminal */ -const util = require('util'); +const util = require("util"); function test(test_name, actual, expected) { - let status; - if (actual === expected) { - status = "PASSED"; - } else { - status = `FAILED: expected: ${util.inspect(expected)} but your function returned: ${util.inspect(actual)}`; - } - - console.log(`${test_name}: ${status}`); + let status; + if (actual === expected) { + status = "PASSED"; + } else { + status = `FAILED: expected: ${util.inspect( + expected + )} but your function returned: ${util.inspect(actual)}`; + } + + console.log(`${test_name}: ${status}`); } test("convertToUSD function works", convertToUSD(32), 44.8); From 4a7a7a156bf630b5855f029fa518e0bdfe13dec0 Mon Sep 17 00:00:00 2001 From: osagiestar Date: Fri, 10 Jul 2020 12:04:56 +0100 Subject: [PATCH 83/84] debugging --- week-3/2-mandatory/6-lane-names.js | 47 +++++++----------------------- 1 file changed, 10 insertions(+), 37 deletions(-) diff --git a/week-3/2-mandatory/6-lane-names.js b/week-3/2-mandatory/6-lane-names.js index e650c6d..245047e 100644 --- a/week-3/2-mandatory/6-lane-names.js +++ b/week-3/2-mandatory/6-lane-names.js @@ -21,49 +21,22 @@ const streetNames = [ "Alban Highwalk", ]; -<<<<<<< HEAD -function arraysEqual(a, b) { - if (a === b) return true; - if (a == null || b == null) return false; - if (a.length != b.length) return false; +const util = require("util"); - for (let i = 0; i < a.length; ++i) { - if (a[i] !== b[i]) return false; - } - - return true; -} - -function test(test_name, expr) { +function test(test_name, actual, expected) { let status; - if (expr) { + if (util.isDeepStrictEqual(actual, expected)) { status = "PASSED"; } else { - status = "FAILED"; + status = `FAILED: expected: ${util.inspect( + expected + )} but your function returned: ${util.inspect(actual)}`; } console.log(`${test_name}: ${status}`); -======= -const util = require('util'); - -function test(test_name, actual, expected) { - let status; - if (util.isDeepStrictEqual(actual, expected)) { - status = "PASSED"; - } else { - status = `FAILED: expected: ${util.inspect(expected)} but your function returned: ${util.inspect(actual)}`; - } - - console.log(`${test_name}: ${status}`); ->>>>>>> 8d17c19782cb831f7eeeb6c2adc0555b17d81af4 } -test( - "getLanes function works", -<<<<<<< HEAD - arraysEqual(getLanes(streetNames), ["Abchurch Lane", "Addle Lane"]) -======= - getLanes(streetNames), - ["Abchurch Lane", "Addle Lane"] ->>>>>>> 8d17c19782cb831f7eeeb6c2adc0555b17d81af4 -); +test("getLanes function works", getLanes(streetNames), [ + "Abchurch Lane", + "Addle Lane", +]); From 0bf0f1f4b68b9f29b67e63be6f1b17b18e82dc8c Mon Sep 17 00:00:00 2001 From: osagiestar Date: Fri, 10 Jul 2020 12:06:27 +0100 Subject: [PATCH 84/84] debugging --- week-1/2-mandatory/3-function-output.js | 33 +++++++++++-------------- 1 file changed, 15 insertions(+), 18 deletions(-) diff --git a/week-1/2-mandatory/3-function-output.js b/week-1/2-mandatory/3-function-output.js index bb1dd1f..ec196d2 100644 --- a/week-1/2-mandatory/3-function-output.js +++ b/week-1/2-mandatory/3-function-output.js @@ -1,7 +1,7 @@ // Add comments to explain what this function does. You're meant to use Google! function letterSet() { return Math.random() * 10; //Math.random() syntax is a floating-point, pseudo-random number between 0 (inclusive) and 1 (exclusive). -} +} //This will return random numbers between 0 to 9: 0, 1, 2, 3, 4, 5, 6, 7, 8, 9. // Add comments to explain what this function does. You're meant to use Google! function words(w1, w2, w3) { @@ -10,15 +10,10 @@ function words(w1, w2, w3) { /*Option 2: return w1.concat(w2, w3);*/ function concatenate(firstWord, secondWord, thirdWord) { -<<<<<<< HEAD // Write the body of this function to concatenate three words together // Look at the test case below to understand what to expect in return return `${firstWord} ${secondWord} ${thirdWord}`; -======= - // Write the body of this function to concatenate three words together. - // Look at the test case below to understand what this function is expected to return. ->>>>>>> 8d17c19782cb831f7eeeb6c2adc0555b17d81af4 } /* ======= TESTS - DO NOT MODIFY ===== @@ -26,31 +21,33 @@ There are some Tests in this file that will help you work out if your code is wo To run these tests type `node 3-function-output` into your terminal */ -const util = require('util'); +const util = require("util"); function test(test_name, actual, expected) { - let status; - if (actual === expected) { - status = "PASSED"; - } else { - status = `FAILED: expected: ${util.inspect(expected)} but your function returned: ${util.inspect(actual)}`; - } - - console.log(`${test_name}: ${status}`); + let status; + if (actual === expected) { + status = "PASSED"; + } else { + status = `FAILED: expected: ${util.inspect( + expected + )} but your function returned: ${util.inspect(actual)}`; + } + + console.log(`${test_name}: ${status}`); } test( "concatenate function - case 1 works", - concatenate('code', 'your', 'future'), + concatenate("code", "your", "future"), "code your future" ); test( "concatenate function - case 2 works", - concatenate('I', 'like', 'pizza'), + concatenate("I", "like", "pizza"), "I like pizza" ); test( "concatenate function - case 3 works", - concatenate('I', 'am', 13), + concatenate("I", "am", 13), "I am 13" );