From 112402f46d65d8cb6c8ae5cb27d91c7c4eb0408a Mon Sep 17 00:00:00 2001 From: bireworld Date: Fri, 19 Jun 2020 22:45:16 +0100 Subject: [PATCH 01/45] exercise done B-hello-world --- week-1/1-exercises/B-hello-world/exercise.js | 3 ++- 1 file changed, 2 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..cc7e44f 100644 --- a/week-1/1-exercises/B-hello-world/exercise.js +++ b/week-1/1-exercises/B-hello-world/exercise.js @@ -1 +1,2 @@ -console.log("Hello world"); +console.log("Hello world. I just started learning javascript"); +console.log(2020); From 82da683c4cb6e6cca25bc3065bf07354b43f1448 Mon Sep 17 00:00:00 2001 From: bireworld Date: Fri, 19 Jun 2020 22:46:45 +0100 Subject: [PATCH 02/45] exercise done C-variables --- week-1/1-exercises/C-variables/exercise.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/week-1/1-exercises/C-variables/exercise.js b/week-1/1-exercises/C-variables/exercise.js index a6bbb97..a1af969 100644 --- a/week-1/1-exercises/C-variables/exercise.js +++ b/week-1/1-exercises/C-variables/exercise.js @@ -1,3 +1,5 @@ // Start by creating a variable `greeting` - +var greeting = "Hello World!"; +console.log(greeting); +console.log(greeting); console.log(greeting); From 375a8784d969a33c4f00deaac37dc6e9d9e2e08b Mon Sep 17 00:00:00 2001 From: bireworld Date: Fri, 19 Jun 2020 22:50:41 +0100 Subject: [PATCH 03/45] exercise done D-strings --- week-1/1-exercises/D-strings/exercise.js | 3 +++ 1 file changed, 3 insertions(+) diff --git a/week-1/1-exercises/D-strings/exercise.js b/week-1/1-exercises/D-strings/exercise.js index 2cffa6a..2d108e2 100644 --- a/week-1/1-exercises/D-strings/exercise.js +++ b/week-1/1-exercises/D-strings/exercise.js @@ -1,3 +1,6 @@ // Start by creating a variable `message` +var message = "This is a string"; +var messageType = typeof message; +console.log(messageType); // logs 'string' console.log(message); From a6f2b32e87cb69720c24373538f54c5c4d5dbdd0 Mon Sep 17 00:00:00 2001 From: bireworld Date: Fri, 19 Jun 2020 22:53:57 +0100 Subject: [PATCH 04/45] exercise done E-strings-concatenation --- week-1/1-exercises/E-strings-concatenation/exercise.js | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/week-1/1-exercises/E-strings-concatenation/exercise.js b/week-1/1-exercises/E-strings-concatenation/exercise.js index 2cffa6a..6943e8c 100644 --- a/week-1/1-exercises/E-strings-concatenation/exercise.js +++ b/week-1/1-exercises/E-strings-concatenation/exercise.js @@ -1,3 +1,7 @@ // Start by creating a variable `message` +var greetingStart = "Hello, my name is "; +var name = "Berhane"; -console.log(message); +var greeting = greetingStart + name; + +console.log(greeting); // Logs "Hello, my name is Daniel" From 2d5a4e4b0da7b0adf2b9f2c46c0dc47625fd2db5 Mon Sep 17 00:00:00 2001 From: bireworld Date: Fri, 19 Jun 2020 23:07:45 +0100 Subject: [PATCH 05/45] exercise1 done F-strings-method --- week-1/1-exercises/F-strings-methods/exercise.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/week-1/1-exercises/F-strings-methods/exercise.js b/week-1/1-exercises/F-strings-methods/exercise.js index 2cffa6a..3b95944 100644 --- a/week-1/1-exercises/F-strings-methods/exercise.js +++ b/week-1/1-exercises/F-strings-methods/exercise.js @@ -1,3 +1,6 @@ // Start by creating a variable `message` - +var name = "Berhane"; +var nameLength = name.length; +var message = "My name is " + name +" and my name is " + nameLength + " characters long" +console.log(nameLength); // Logs 6 console.log(message); From ee55d1560e155173f4f2f53826d6a0e29462a458 Mon Sep 17 00:00:00 2001 From: bireworld Date: Fri, 19 Jun 2020 23:14:16 +0100 Subject: [PATCH 06/45] exercise2 done F-strings-method --- week-1/1-exercises/F-strings-methods/exercise2.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/week-1/1-exercises/F-strings-methods/exercise2.js b/week-1/1-exercises/F-strings-methods/exercise2.js index b4b4694..068ec34 100644 --- a/week-1/1-exercises/F-strings-methods/exercise2.js +++ b/week-1/1-exercises/F-strings-methods/exercise2.js @@ -1,3 +1,3 @@ -const name = " Daniel "; - -console.log(message); +const name = " My name is Berhane and my name is 7 characters long "; +name.trim(); +console.log(name); From 870aa1c85cfc1b7eeac9d4f042a92bd4f2b5fc5b Mon Sep 17 00:00:00 2001 From: bireworld Date: Fri, 19 Jun 2020 23:20:00 +0100 Subject: [PATCH 07/45] exercise done G-numbers --- week-1/1-exercises/G-numbers/exercise.js | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/week-1/1-exercises/G-numbers/exercise.js b/week-1/1-exercises/G-numbers/exercise.js index 49e7bc0..f92d940 100644 --- a/week-1/1-exercises/G-numbers/exercise.js +++ b/week-1/1-exercises/G-numbers/exercise.js @@ -1 +1,5 @@ // Start by creating a variables `numberOfStudents` and `numberOfMentors` +var numberOfStudents = 15; +var numberOfMentors = 8; +var sum = numberOfStudents + numberOfMentors; +console.log("Total numnber of students and mentors:" + sum); From 3e8e82cdd6cc7352d2a5e010136729366f16b939 Mon Sep 17 00:00:00 2001 From: bireworld Date: Fri, 19 Jun 2020 23:39:44 +0100 Subject: [PATCH 08/45] exercise done I-floats --- week-1/1-exercises/I-floats/exercise.js | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/week-1/1-exercises/I-floats/exercise.js b/week-1/1-exercises/I-floats/exercise.js index a5bbcd8..14730c2 100644 --- a/week-1/1-exercises/I-floats/exercise.js +++ b/week-1/1-exercises/I-floats/exercise.js @@ -1,2 +1,7 @@ var numberOfStudents = 15; var numberOfMentors = 8; +var stuPercentile = numberOfStudents/23*100; +var mentorpercentile = numberOfMentors/23*100; +console.log("Percentage Students:" +stuPercentile + "%" ); +console.log("Percentage Mentors:" + mentorpercentile + "%"); + From 8373dd5b49af65a43a6181b5f06a4702e46b3ee0 Mon Sep 17 00:00:00 2001 From: bireworld Date: Fri, 19 Jun 2020 23:42:14 +0100 Subject: [PATCH 09/45] exercise done I-floats update --- week-1/1-exercises/I-floats/exercise.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/week-1/1-exercises/I-floats/exercise.js b/week-1/1-exercises/I-floats/exercise.js index 14730c2..f88e40a 100644 --- a/week-1/1-exercises/I-floats/exercise.js +++ b/week-1/1-exercises/I-floats/exercise.js @@ -2,6 +2,8 @@ var numberOfStudents = 15; var numberOfMentors = 8; var stuPercentile = numberOfStudents/23*100; var mentorpercentile = numberOfMentors/23*100; +stuPercentile = Math.round(stuPercentile); +mentorpercentile = Math.round(mentorpercentile); console.log("Percentage Students:" +stuPercentile + "%" ); console.log("Percentage Mentors:" + mentorpercentile + "%"); From f5bc22432e3ccc3cb848dd2fce967f5a0bfc00b9 Mon Sep 17 00:00:00 2001 From: bireworld Date: Fri, 19 Jun 2020 23:46:59 +0100 Subject: [PATCH 10/45] exercise done J-functions --- week-1/1-exercises/J-functions/exercise.js | 1 + 1 file changed, 1 insertion(+) diff --git a/week-1/1-exercises/J-functions/exercise.js b/week-1/1-exercises/J-functions/exercise.js index 0ae5850..e9ba2f0 100644 --- a/week-1/1-exercises/J-functions/exercise.js +++ b/week-1/1-exercises/J-functions/exercise.js @@ -1,5 +1,6 @@ function halve(number) { // complete the function here + return number/2; } var result = halve(12); From 45bbcb7456d1ebb43e8341f5315d327ab572c152 Mon Sep 17 00:00:00 2001 From: bireworld Date: Fri, 19 Jun 2020 23:49:15 +0100 Subject: [PATCH 11/45] exercise done J-functions --- week-1/1-exercises/J-functions/exercise.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/week-1/1-exercises/J-functions/exercise.js b/week-1/1-exercises/J-functions/exercise.js index e9ba2f0..c1b5db3 100644 --- a/week-1/1-exercises/J-functions/exercise.js +++ b/week-1/1-exercises/J-functions/exercise.js @@ -4,5 +4,8 @@ function halve(number) { } var result = halve(12); - +var result2 = halve(32); +var result3 = halve(3); console.log(result); +console.log(result2); +console.log(result3); From ca4400708cdeba988faa82608773828f06c7fdc8 Mon Sep 17 00:00:00 2001 From: bireworld Date: Fri, 19 Jun 2020 23:50:45 +0100 Subject: [PATCH 12/45] exercise2 done J-functions --- week-1/1-exercises/J-functions/exercise2.js | 1 + 1 file changed, 1 insertion(+) diff --git a/week-1/1-exercises/J-functions/exercise2.js b/week-1/1-exercises/J-functions/exercise2.js index 82ef5e7..468d455 100644 --- a/week-1/1-exercises/J-functions/exercise2.js +++ b/week-1/1-exercises/J-functions/exercise2.js @@ -1,5 +1,6 @@ function triple(number) { // complete function here + return number * 3; } var result = triple(12); From 4b56746e1905a5549a45933d12bc9e217130b7da Mon Sep 17 00:00:00 2001 From: bireworld Date: Fri, 19 Jun 2020 23:54:28 +0100 Subject: [PATCH 13/45] exercise done K-functions-parameters --- week-1/1-exercises/K-functions-parameters/exercise.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/week-1/1-exercises/K-functions-parameters/exercise.js b/week-1/1-exercises/K-functions-parameters/exercise.js index 8d5db5e..71969d1 100644 --- a/week-1/1-exercises/K-functions-parameters/exercise.js +++ b/week-1/1-exercises/K-functions-parameters/exercise.js @@ -1,6 +1,7 @@ // Complete the function so that it takes input parameters -function multiply() { +function multiply(num1,num2) { // Calculate the result of the function and return it + return num1 * num2; } // Assign the result of calling the function the variable `result` From 455ba21f520416c45b7bfa7711e2cdebe2a0b290 Mon Sep 17 00:00:00 2001 From: bireworld Date: Fri, 19 Jun 2020 23:56:28 +0100 Subject: [PATCH 14/45] exercise2 done K-functions-parameters --- week-1/1-exercises/K-functions-parameters/exercise2.js | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/week-1/1-exercises/K-functions-parameters/exercise2.js b/week-1/1-exercises/K-functions-parameters/exercise2.js index db7a890..1dcf0e0 100644 --- a/week-1/1-exercises/K-functions-parameters/exercise2.js +++ b/week-1/1-exercises/K-functions-parameters/exercise2.js @@ -1,5 +1,10 @@ // Declare your function first +function divide(num1, num2) { + // Calculate the result of the function and return it + return num1 / num2; +} +// Assign the result of calling the function the variable `result` var result = divide(3, 4); console.log(result); From dd3dd6dea650121477a80a10fe80ea4372288d7f Mon Sep 17 00:00:00 2001 From: bireworld Date: Sat, 20 Jun 2020 00:02:07 +0100 Subject: [PATCH 15/45] exercise3 done K-functions-parameters --- week-1/1-exercises/K-functions-parameters/exercise3.js | 3 +++ 1 file changed, 3 insertions(+) diff --git a/week-1/1-exercises/K-functions-parameters/exercise3.js b/week-1/1-exercises/K-functions-parameters/exercise3.js index 537e9f4..fbfbf0c 100644 --- a/week-1/1-exercises/K-functions-parameters/exercise3.js +++ b/week-1/1-exercises/K-functions-parameters/exercise3.js @@ -1,4 +1,7 @@ // Write your function here +function createGreeting(name){ + return "Hello, my name is " + name; +} var greeting = createGreeting("Daniel"); From fe488ea150d7898bb3acc26ad8bbd3aced7737ce Mon Sep 17 00:00:00 2001 From: bireworld Date: Sat, 20 Jun 2020 00:05:10 +0100 Subject: [PATCH 16/45] exercise4 done K-functions-parameters --- week-1/1-exercises/K-functions-parameters/exercise4.js | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/week-1/1-exercises/K-functions-parameters/exercise4.js b/week-1/1-exercises/K-functions-parameters/exercise4.js index 7ab4458..067cb5f 100644 --- a/week-1/1-exercises/K-functions-parameters/exercise4.js +++ b/week-1/1-exercises/K-functions-parameters/exercise4.js @@ -1,4 +1,9 @@ // Declare your function first +function addition(num1, num2) { + return num1 + num2; +} + +sum = addition(13, 124); // Call the function and assign to a variable `sum` From 4d43363457d3000ca158f872497b901deef6e9ff Mon Sep 17 00:00:00 2001 From: bireworld Date: Sat, 20 Jun 2020 00:07:51 +0100 Subject: [PATCH 17/45] exercise5 done K-functions-parameters --- week-1/1-exercises/K-functions-parameters/exercise5.js | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/week-1/1-exercises/K-functions-parameters/exercise5.js b/week-1/1-exercises/K-functions-parameters/exercise5.js index 7c5bcd6..23d1783 100644 --- a/week-1/1-exercises/K-functions-parameters/exercise5.js +++ b/week-1/1-exercises/K-functions-parameters/exercise5.js @@ -1,4 +1,8 @@ // Declare your function here +function createLongGreeting(name, age){ + return "Hello, my name is " + name + " and I'm " + age + " years old" + +} const greeting = createLongGreeting("Daniel", 30); From 64e0da94f7bdbfe2c452508dff5aef378e252203 Mon Sep 17 00:00:00 2001 From: bireworld Date: Sat, 20 Jun 2020 00:55:14 +0100 Subject: [PATCH 18/45] syntax corrected --- week-1/2-mandatory/1-syntax-errors.js | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/week-1/2-mandatory/1-syntax-errors.js b/week-1/2-mandatory/1-syntax-errors.js index 6910f28..353fb45 100644 --- a/week-1/2-mandatory/1-syntax-errors.js +++ b/week-1/2-mandatory/1-syntax-errors.js @@ -2,18 +2,19 @@ // 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"; +function introduceMe(name, age){ +return "Hello, my name is " + name + " and I am " + age + " years old"; +} -function getAddition(a, b) { - total = a ++ b +function getRemainder(a, b) { + // Use string interpolation here - return "The total is %{total}" + return `The remainder is ${a%b}`; } /* ======= TESTS - DO NOT MODIFY ===== */ @@ -23,12 +24,12 @@ function getAddition(a, b) { 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 addNumbers function - case 1", addNumbers(3,4,6) === 13) From 8c623d686397c5d50d3dbb745b9bc2bf5ff348a0 Mon Sep 17 00:00:00 2001 From: bireworld Date: Sat, 20 Jun 2020 01:03:46 +0100 Subject: [PATCH 19/45] logic error corrected --- week-1/2-mandatory/2-logic-error.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/week-1/2-mandatory/2-logic-error.js b/week-1/2-mandatory/2-logic-error.js index 1e0a9d4..f64f61a 100644 --- a/week-1/2-mandatory/2-logic-error.js +++ b/week-1/2-mandatory/2-logic-error.js @@ -1,16 +1,16 @@ // The syntax for this function is valid but it has an error, find it and fix it. function trimWord(word) { - return wordtrim(); + return word.trim(); } 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 ===== From 01f6bf68ff8db3c33fda55d4616eeed5f96e7955 Mon Sep 17 00:00:00 2001 From: bireworld Date: Sat, 20 Jun 2020 01:16:17 +0100 Subject: [PATCH 20/45] function output error corrected --- week-1/2-mandatory/3-function-output.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/week-1/2-mandatory/3-function-output.js b/week-1/2-mandatory/3-function-output.js index bbb88a2..0231107 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; + return Math.random() * 10; // returns a random integer from 0 to 9 + } // Add comments to explain what this function does. You're meant to use Google! function s(w1, w2) { - return w1.concat(w2); + return w1.concat(w2); // concatenates w1(string 1) with w2(string 2) } 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 3bf68ab00c8874657156e892fd590356ff41e6c6 Mon Sep 17 00:00:00 2001 From: bireworld Date: Sat, 20 Jun 2020 01:36:51 +0100 Subject: [PATCH 21/45] tax calcultated --- week-1/2-mandatory/4-tax.js | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/week-1/2-mandatory/4-tax.js b/week-1/2-mandatory/4-tax.js index 6b84208..b61c6b4 100644 --- a/week-1/2-mandatory/4-tax.js +++ b/week-1/2-mandatory/4-tax.js @@ -5,7 +5,12 @@ Sales tax is 20% of the price of the product */ -function calculateSalesTax() {} +function calculateSalesTax(productPrice) { + + var salesTax = 0.2 * productPrice; + return productPrice+salesTax; + +} /* CURRENCY FORMATTING @@ -17,7 +22,11 @@ function calculateSalesTax() {} Remember that the prices must include the sales tax (hint: you already wrote a function for this!) */ -function formatCurrency() {} +function formatCurrency(price) { + var totPrice = calculateSalesTax(price); + totPrice = totPrice.toFixed(2); + return "£"+totPrice; +} /* ======= TESTS - DO NOT MODIFY ===== There are some Tests in this file that will help you work out if your code is working. From 5e88c3f9b9343aaaf764c4125c151a3b91bbe6e2 Mon Sep 17 00:00:00 2001 From: bireworld Date: Sun, 21 Jun 2020 03:55:16 +0100 Subject: [PATCH 22/45] currency conversion done --- week-1/3-extra/1-currency-conversion.js | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/week-1/3-extra/1-currency-conversion.js b/week-1/3-extra/1-currency-conversion.js index 7f321d9..d31f3ed 100644 --- a/week-1/3-extra/1-currency-conversion.js +++ b/week-1/3-extra/1-currency-conversion.js @@ -5,7 +5,10 @@ Write a function that converts a price to USD (exchange rate is 1.4 $ to £) */ -function convertToUSD() {} +function convertToUSD(amountPound) { + var amountUSD = amountPound*1.4 + return amountUSD +} /* CURRENCY FORMATTING @@ -16,7 +19,14 @@ function convertToUSD() {} Find a way to add 1% to all currency conversions (think about the DRY principle) */ -function convertToBRL() {} +function convertToBRL(amountInPound) { + + var amountBRL = amountInPound * 5.7 + amountBRL += amountBRL*0.01 + return amountBRL + +} +console.log(convertToBRL(30)) /* ======= TESTS - DO NOT MODIFY ===== There are some Tests in this file that will help you work out if your code is working. From 02b63aa6c8dfb03e18102672c9c748c47495a84b Mon Sep 17 00:00:00 2001 From: bireworld Date: Sun, 21 Jun 2020 11:08:11 +0100 Subject: [PATCH 23/45] piping done --- week-1/3-extra/2-piping.js | 37 +++++++++++++++++++------------------ 1 file changed, 19 insertions(+), 18 deletions(-) diff --git a/week-1/3-extra/2-piping.js b/week-1/3-extra/2-piping.js index 93c0bf7..33c6a4d 100644 --- a/week-1/3-extra/2-piping.js +++ b/week-1/3-extra/2-piping.js @@ -16,26 +16,27 @@ the final result to the variable goodCode */ -function add() { - +function add(num1, num2) { + return ((num1*10) + (num2*10))/10; } -function multiply() { - +function multiply(num1, num2) { + return num1 * num2; } -function format() { - +function format(num) { + return "£" + num; } -const startingValue = 2 +const startingValue = 2; // Why can this code be seen as bad practice? Comment your answer. -let badCode = +/* we have easier ways applying the already created functions for more flexibility */ +let badCode = "£" + add(startingValue, 10) * 2; /* BETTER PRACTICE */ -let goodCode = +let goodCode = format(multiply(add(startingValue, 10), 2)); /* ======= TESTS - DO NOT MODIFY ===== There are some Tests in this file that will help you work out if your code is working. @@ -46,17 +47,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 dddd5b21b57538c252ae905cf6d4f8cbaaeea648 Mon Sep 17 00:00:00 2001 From: bireworld Date: Mon, 22 Jun 2020 07:12:41 +0100 Subject: [PATCH 24/45] magic 8 ball done --- week-1/3-extra/3-magic-8-ball.js | 25 ++++++++++++++++++++++--- 1 file changed, 22 insertions(+), 3 deletions(-) diff --git a/week-1/3-extra/3-magic-8-ball.js b/week-1/3-extra/3-magic-8-ball.js index 1bb1089..9114845 100644 --- a/week-1/3-extra/3-magic-8-ball.js +++ b/week-1/3-extra/3-magic-8-ball.js @@ -45,17 +45,36 @@ Very doubtful. // This should log "The ball has shaken!" // and return the answer. -function shakeBall() {} +function shakeBall(answer) { + + console.log("The ball has shaken!") + + return "The ball has shaken!" + +} // The answer should come from shaking the ball -let answer; +let answer = ["very positive", "positive", "negative", "very negative"]; // When checking the answer, we should tell someone if the answer is // - very positive // - positive // - negative // - very negative -function checkAnswer() {} +function checkAnswer() { + for(let i=0;i Date: Mon, 22 Jun 2020 08:17:27 +0100 Subject: [PATCH 25/45] boolean exercise done --- week-2/1-exercises/B-boolean-literals/exercise.js | 3 +++ 1 file changed, 3 insertions(+) diff --git a/week-2/1-exercises/B-boolean-literals/exercise.js b/week-2/1-exercises/B-boolean-literals/exercise.js index 6c5060f..6e0c98c 100644 --- a/week-2/1-exercises/B-boolean-literals/exercise.js +++ b/week-2/1-exercises/B-boolean-literals/exercise.js @@ -6,6 +6,9 @@ */ var codeYourFutureIsGreat = true; +var mozafarIsCool = false; +var calculationCorrect = true; +var moreThan10Students = false; /* DO NOT EDIT BELOW THIS LINE From c21646ca17990b79284fd5fe7f172420aedf3660 Mon Sep 17 00:00:00 2001 From: bireworld Date: Mon, 22 Jun 2020 08:22:33 +0100 Subject: [PATCH 26/45] comparison-operator done --- week-2/1-exercises/C-comparison-operators/exercise.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/week-2/1-exercises/C-comparison-operators/exercise.js b/week-2/1-exercises/C-comparison-operators/exercise.js index 58aee1c..e8a62fb 100644 --- a/week-2/1-exercises/C-comparison-operators/exercise.js +++ b/week-2/1-exercises/C-comparison-operators/exercise.js @@ -7,14 +7,14 @@ var studentCount = 16; var mentorCount = 9; -var moreStudentsThanMentors; // finish this statement +var moreStudentsThanMentors = true; // finish this statement var roomMaxCapacity = 25; -var enoughSpaceInRoom; // finish this statement +var enoughSpaceInRoom = true; // finish this statement var personA = "Daniel"; var personB = "Irina"; -var sameName; // finish this statement +var sameName = false; // finish this statement /* DO NOT EDIT BELOW THIS LINE From 0dd82d0cc7e6e5665fe4c419ab136fade99aa913 Mon Sep 17 00:00:00 2001 From: bireworld Date: Tue, 23 Jun 2020 07:11:49 +0100 Subject: [PATCH 27/45] predicate exercise done --- week-2/1-exercises/D-predicates/exercise.js | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/week-2/1-exercises/D-predicates/exercise.js b/week-2/1-exercises/D-predicates/exercise.js index f600521..9971c86 100644 --- a/week-2/1-exercises/D-predicates/exercise.js +++ b/week-2/1-exercises/D-predicates/exercise.js @@ -7,12 +7,22 @@ // Finish the predicate function to test if the passed number is negative (less than zero) function isNegative(number) { + if (number < 0){ + return true + } + else{ + return false + } + } + // Finish the predicate function to test if the passed number is between 0 and 10 function isBetweenZeroAnd10(number) { - +if (number >=0 && number <=10){ + return true; +} } /* From 1d6f9ce2b123f651ae1b376d8a4278ab3f6a85d2 Mon Sep 17 00:00:00 2001 From: bireworld Date: Tue, 23 Jun 2020 22:18:07 +0100 Subject: [PATCH 28/45] conditionals done --- week-2/1-exercises/E-conditionals/exercise.js | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/week-2/1-exercises/E-conditionals/exercise.js b/week-2/1-exercises/E-conditionals/exercise.js index acbaaa8..eb77e1c 100644 --- a/week-2/1-exercises/E-conditionals/exercise.js +++ b/week-2/1-exercises/E-conditionals/exercise.js @@ -8,6 +8,11 @@ var name = "Daniel"; var danielsRole = "mentor"; +if (name === danielsRole) { + console.log("Hi, I'm Daniel, I'm a mentor."); +} else { + console.log("Hi, I'm Daniel, I'm a student."); +} /* EXPECTED RESULT From bcba34c08ab0551ab937c020c808144f1f25ce2e Mon Sep 17 00:00:00 2001 From: bireworld Date: Wed, 24 Jun 2020 21:56:18 +0100 Subject: [PATCH 29/45] week-2 fix functio done --- week-2/2-mandatory/1-fix-functions.js | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/week-2/2-mandatory/1-fix-functions.js b/week-2/2-mandatory/1-fix-functions.js index 6316fad..1595b56 100644 --- a/week-2/2-mandatory/1-fix-functions.js +++ b/week-2/2-mandatory/1-fix-functions.js @@ -1,21 +1,21 @@ // The below functions are syntactically correct but not outputting the right results. // Look at the tests and see how you can fix them. -function mood() { - let isHappy = true; +function mood(isHappy) { + //let isHappy = true; - if (isHappy) { + if (isHappy === true) { return "I am happy"; } else { return "I am not happy"; } } -function greaterThan10() { - let num = 10; - let isBigEnough; +function greaterThan10(num) { + num = 10; + //isBigEnough = 10; - if (isBigEnough) { + if (num >= 10) { return "num is greater than or equal to 10"; } else { return "num is not big enough"; @@ -24,21 +24,21 @@ function greaterThan10() { function sortArray() { let letters = ["a", "n", "c", "e", "z", "f"]; - let sortedLetters; + let sortedLetters = letters.sort(); return sortedLetters; } 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 element = arr[3]; return element; } From 2249b0499f4ef6a1c0b82980cfe7c9992494db8e Mon Sep 17 00:00:00 2001 From: bireworld Date: Fri, 26 Jun 2020 23:16:56 +0100 Subject: [PATCH 30/45] function creation done --- week-2/2-mandatory/2-function-creation.js | 30 ++++++++++++++++++++--- 1 file changed, 27 insertions(+), 3 deletions(-) diff --git a/week-2/2-mandatory/2-function-creation.js b/week-2/2-mandatory/2-function-creation.js index bf7ecfd..1a10cef 100644 --- a/week-2/2-mandatory/2-function-creation.js +++ b/week-2/2-mandatory/2-function-creation.js @@ -5,7 +5,13 @@ Write a function that: - removes any forward slashes (/) in the strings - makes the string all lowercase */ -function tidyUpString(strArr) {} +function tidyUpString(strArr) { + let newArr = strArr.map(item => item.trim().replace('/', '').toLowerCase()); + return newArr; +} + + + /* Complete the function to check if the variable `num` satisfies the following requirements: @@ -15,7 +21,14 @@ Complete the function to check if the variable `num` satisfies the following req Tip: use logical operators */ -function validate(num) {} +function validate(num) { + if(typeof num === 'number' && num % 2 == 0 && num <=100){ + return true + } + else{ + return false + } +} /* Write a function that removes an element from an array @@ -26,7 +39,10 @@ The function must: */ function remove(arr, index) { - return; // complete this statement + let newArr = arr + newArr.splice(index,1) + + return newArr; // complete this statement } /* @@ -38,6 +54,14 @@ Write a function that: */ function formatPercentage(arr) { + let newArr = arr.map( item =>{ + if(item > 100 ){ + item = 100 + } + return `${Number(item.toFixed(2))}%`; + + }) + return newArr } From 253bf68ce1d1ce4559867eef6552586bd74a1a59 Mon Sep 17 00:00:00 2001 From: bireworld Date: Fri, 26 Jun 2020 23:44:14 +0100 Subject: [PATCH 31/45] playing computer done --- week-2/2-mandatory/3-playing-computer.js | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/week-2/2-mandatory/3-playing-computer.js b/week-2/2-mandatory/3-playing-computer.js index 0fa7c04..6a2bc9d 100644 --- a/week-2/2-mandatory/3-playing-computer.js +++ b/week-2/2-mandatory/3-playing-computer.js @@ -7,12 +7,19 @@ Answer the following questions: 1. This program throws an error. Why? (If you can't find it, try executing it). + its because b as not defined 2. Remove the line that throws the error. + the error was on console.log(b) now removed 3. What is printed to the console? - 4. How many times is "f1" called? + after removing the error code the output on the console is 2 6 4 9 6 13 8 + 4. How many times is "f1" called? + Twice 5. How many times is "f2" called? - 6. What value does the "a" parameter take in the first "f1" call? - 7. What is the value of the "a" outer variable when "f1" is called for the first time? + Three times + 6. What value does the "a" parameter take in the first "f1" call? + the value as 8 + 7. What is the value of the "a" outer variable when "f1" is called for the first time? + it was 6 */ let x = 2; @@ -28,7 +35,7 @@ const f2 = function(a, b) { console.log(x); console.log(a); -console.log(b); + for (let i = 0; i < 5; ++i) { a = a + 1; @@ -40,3 +47,4 @@ for (let i = 0; i < 5; ++i) { console.log(e); } } + From 5e929310a6cdb09b1331dccd082fd6211dedef81 Mon Sep 17 00:00:00 2001 From: bireworld Date: Sat, 27 Jun 2020 00:02:28 +0100 Subject: [PATCH 32/45] sorting algot=rith done --- week-2/2-mandatory/4-sorting-algorithm.js | 25 ++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/week-2/2-mandatory/4-sorting-algorithm.js b/week-2/2-mandatory/4-sorting-algorithm.js index 3603942..042060d 100644 --- a/week-2/2-mandatory/4-sorting-algorithm.js +++ b/week-2/2-mandatory/4-sorting-algorithm.js @@ -14,7 +14,30 @@ 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) { + let newArr = [] + for(let i=0;i newArr[i]) { + done = false; + var tmp = newArr[i - 1]; + newArr[i - 1] = newArr[i]; + newArr[i] = tmp; + } + } + } + + return newArr; +} + //console.log(newArr) /* ======= TESTS - DO NOT MODIFY ===== */ From ca482f09986006a45c69cf9ee8cae7639c21f484 Mon Sep 17 00:00:00 2001 From: bireworld Date: Mon, 29 Jun 2020 22:02:41 +0100 Subject: [PATCH 33/45] oxygen level completed --- week-3/2-mandatory/1-oxygen-levels.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/week-3/2-mandatory/1-oxygen-levels.js b/week-3/2-mandatory/1-oxygen-levels.js index 3c02135..e75bb25 100644 --- a/week-3/2-mandatory/1-oxygen-levels.js +++ b/week-3/2-mandatory/1-oxygen-levels.js @@ -9,7 +9,8 @@ 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(oxygenL) { + return oxygenL.find(item=>(item > "19.5%" && item < "23.5%")) } From bcc14f742f5fcdc3b0c97e5b0a5e9733f8db1a77 Mon Sep 17 00:00:00 2001 From: bireworld Date: Wed, 1 Jul 2020 07:31:13 +0100 Subject: [PATCH 34/45] Space colonies completed --- week-3/2-mandatory/3-space-colonies.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/week-3/2-mandatory/3-space-colonies.js b/week-3/2-mandatory/3-space-colonies.js index f99891a..b287d95 100644 --- a/week-3/2-mandatory/3-space-colonies.js +++ b/week-3/2-mandatory/3-space-colonies.js @@ -8,7 +8,8 @@ NOTE: don't include any element that is not a "family". */ -function colonisers() { +function colonisers(names) { + return names.filter(element => element.charAt(0)==="A" && element.includes("family")) } From 32a3830390347254e44d1a8b1f4771c023047be0 Mon Sep 17 00:00:00 2001 From: bireworld Date: Thu, 2 Jul 2020 23:06:16 +0100 Subject: [PATCH 35/45] H array methods exercise2 completed --- week-3/1-exercises/H-array-methods-2/exercise2.js | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/week-3/1-exercises/H-array-methods-2/exercise2.js b/week-3/1-exercises/H-array-methods-2/exercise2.js index b7be576..d3fd27c 100644 --- a/week-3/1-exercises/H-array-methods-2/exercise2.js +++ b/week-3/1-exercises/H-array-methods-2/exercise2.js @@ -7,7 +7,20 @@ Tip: use the string method .split() and the array method .join() */ -function capitalise(str) {} +function capitalise(str) { + //firstChar = str[0] + str = str.split(''); + str[0]= str[0].toUpperCase() + + str = str.join('') + return str + //str.join("") + + //console.log(str) + //newStr.join(firstChar.toUpperCase()) + + +} /* DO NOT EDIT BELOW THIS LINE From f286309582024259d985c5c3a06e9bda74115abb Mon Sep 17 00:00:00 2001 From: bireworld Date: Thu, 2 Jul 2020 23:08:27 +0100 Subject: [PATCH 36/45] H array methods exercise2 completed --- week-3/1-exercises/H-array-methods-2/exercise2.js | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/week-3/1-exercises/H-array-methods-2/exercise2.js b/week-3/1-exercises/H-array-methods-2/exercise2.js index d3fd27c..99d11f8 100644 --- a/week-3/1-exercises/H-array-methods-2/exercise2.js +++ b/week-3/1-exercises/H-array-methods-2/exercise2.js @@ -8,18 +8,13 @@ */ function capitalise(str) { - //firstChar = str[0] + str = str.split(''); str[0]= str[0].toUpperCase() str = str.join('') return str - //str.join("") - - //console.log(str) - //newStr.join(firstChar.toUpperCase()) - - + } /* From 844c93d0593839bdb85133f255cc14d658e9f94b Mon Sep 17 00:00:00 2001 From: bireworld Date: Thu, 2 Jul 2020 23:14:07 +0100 Subject: [PATCH 37/45] H array methods exercise completed --- week-3/1-exercises/H-array-methods-2/exercise.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/week-3/1-exercises/H-array-methods-2/exercise.js b/week-3/1-exercises/H-array-methods-2/exercise.js index d36303b..cca17b4 100644 --- a/week-3/1-exercises/H-array-methods-2/exercise.js +++ b/week-3/1-exercises/H-array-methods-2/exercise.js @@ -15,8 +15,10 @@ var everyone = [ "Swathi" ]; -var firstFive; // complete this statement -var lastFive; // complete this statement +var firstFive =everyone.slice(0,5); // complete this statement +//console.log(firstFive) +var lastFive = everyone.slice(2,7); // complete this statement +//console.log(lastFive) /* DO NOT EDIT BELOW THIS LINE From 0ce0c4df45df4cc3656bed83bca4ce278b676cc6 Mon Sep 17 00:00:00 2001 From: bireworld Date: Thu, 2 Jul 2020 23:20:01 +0100 Subject: [PATCH 38/45] H array methods exercise3 completed --- week-3/1-exercises/H-array-methods-2/exercise3.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/week-3/1-exercises/H-array-methods-2/exercise3.js b/week-3/1-exercises/H-array-methods-2/exercise3.js index 82e9dd8..75a6b76 100644 --- a/week-3/1-exercises/H-array-methods-2/exercise3.js +++ b/week-3/1-exercises/H-array-methods-2/exercise3.js @@ -7,7 +7,7 @@ var ukNations = ["Scotland", "Wales", "England", "Northern Ireland"]; function isInUK(country) { - return; // complete this statement + return ukNations.includes(country); // complete this statement } /* From 35d47e3d2f3412fbdf9eb4fb5183c8c00314f5d1 Mon Sep 17 00:00:00 2001 From: bireworld Date: Thu, 2 Jul 2020 23:22:26 +0100 Subject: [PATCH 39/45] G array methods exercise completed --- week-3/1-exercises/G-array-methods/exercise.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/week-3/1-exercises/G-array-methods/exercise.js b/week-3/1-exercises/G-array-methods/exercise.js index 44e9c80..6a8e4b3 100644 --- a/week-3/1-exercises/G-array-methods/exercise.js +++ b/week-3/1-exercises/G-array-methods/exercise.js @@ -4,7 +4,7 @@ */ var numbers = [3, 2, 1]; -var sortedNumbers; // complete this statement +var sortedNumbers = numbers.sort(); // complete this statement /* DO NOT EDIT BELOW THIS LINE From 670825d465cf2c382e2fd4ab3bcd1412ee380859 Mon Sep 17 00:00:00 2001 From: bireworld Date: Thu, 2 Jul 2020 23:23:55 +0100 Subject: [PATCH 40/45] G array methods exercise2 completed --- week-3/1-exercises/G-array-methods/exercise2.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/week-3/1-exercises/G-array-methods/exercise2.js b/week-3/1-exercises/G-array-methods/exercise2.js index 3dd24a1..dd87089 100644 --- a/week-3/1-exercises/G-array-methods/exercise2.js +++ b/week-3/1-exercises/G-array-methods/exercise2.js @@ -7,7 +7,7 @@ var mentors = ["Daniel", "Irina", "Rares"]; var students = ["Rukmini", "Abdul", "Austine", "Swathi"]; -var everyone; // complete this statement +var everyone = mentors.concat(students); // complete this statement /* DO NOT EDIT BELOW THIS LINE From 381a1efecb064d076be1bc887d73eb902976a012 Mon Sep 17 00:00:00 2001 From: bireworld Date: Thu, 2 Jul 2020 23:53:19 +0100 Subject: [PATCH 41/45] F array-forEach exercise completed --- week-3/1-exercises/F-array-forEach/exercise.js | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/week-3/1-exercises/F-array-forEach/exercise.js b/week-3/1-exercises/F-array-forEach/exercise.js index e83e2df..448a8a1 100644 --- a/week-3/1-exercises/F-array-forEach/exercise.js +++ b/week-3/1-exercises/F-array-forEach/exercise.js @@ -8,6 +8,21 @@ */ var arr = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15]; +arr.forEach(function(number){ + if (number % 15 === 0) { + console.log("FizzBuzz") + } + else if(number%3===0){ + console.log("Fizz") + } + else if(number%5===0){ + console.log("Buzz") + } + + else{ + console.log(number) + } +}) /* EXPECTED OUTPUT */ From ea65690687b6a5e4194504223fd3741edddcb17f Mon Sep 17 00:00:00 2001 From: bireworld Date: Sun, 5 Jul 2020 20:22:54 +0100 Subject: [PATCH 42/45] bush berries completed --- week-3/2-mandatory/2-bush-berries.js | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/week-3/2-mandatory/2-bush-berries.js b/week-3/2-mandatory/2-bush-berries.js index d900323..5ed2a2f 100644 --- a/week-3/2-mandatory/2-bush-berries.js +++ b/week-3/2-mandatory/2-bush-berries.js @@ -9,10 +9,28 @@ Use the tests to confirm which message to return */ +/*function barriesCheck(barries) { + + if (barries[j] === "pink") { + return "Bush is safe to eat from" + } + else { + return "Toxic! Leave bush alone!" + } +} +}*/ -function bushChecker() { +//function bushChecker() { + function barriesColor(color) { + return color == "pink" + } + function bushChecker(arr) { -} + if (arr.every(barriesColor)) { + return "Bush is safe to eat from" + } + return "Toxic! Leave bush alone!" + } /* ======= TESTS - DO NOT MODIFY ===== */ From a52effbc0f37f1558368c8b6809d73cf3658b06d Mon Sep 17 00:00:00 2001 From: bireworld Date: Sun, 5 Jul 2020 21:35:14 +0100 Subject: [PATCH 43/45] eligible students completed --- week-3/2-mandatory/4-eligible-students.js | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/week-3/2-mandatory/4-eligible-students.js b/week-3/2-mandatory/4-eligible-students.js index 6424b01..6e56bbe 100644 --- a/week-3/2-mandatory/4-eligible-students.js +++ b/week-3/2-mandatory/4-eligible-students.js @@ -7,9 +7,17 @@ - Returns an array containing only the names of the who have attended AT LEAST 8 classes */ -function eligibleStudents() { +function eligibleStudents(arr) { + let newArr=[] + for(let i=0;i=8){ + newArr.push(arr[i][0]) + } + } + return newArr + } + -} /* ======= TESTS - DO NOT MODIFY ===== */ From 9916fdeafbfe6dca847b384a62a78721be488553 Mon Sep 17 00:00:00 2001 From: bireworld Date: Sun, 5 Jul 2020 21:41:57 +0100 Subject: [PATCH 44/45] lane-names completed --- week-3/2-mandatory/6-lane-names.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/week-3/2-mandatory/6-lane-names.js b/week-3/2-mandatory/6-lane-names.js index eddfe44..e8f431e 100644 --- a/week-3/2-mandatory/6-lane-names.js +++ b/week-3/2-mandatory/6-lane-names.js @@ -4,7 +4,8 @@ Write a function that will return all street names which contain 'Lane' in their name. */ -function getLanes() { +function getLanes(lane) { + return lane.filter(element => element.includes("Lane")) } From 62d3fb7f94473b7d8e4c3e8cd3498903cf3f2b8a Mon Sep 17 00:00:00 2001 From: bireworld Date: Mon, 6 Jul 2020 21:56:02 +0100 Subject: [PATCH 45/45] password-validator completed --- week-3/2-mandatory/7-password-validator.js | 82 +++++++++++++--------- 1 file changed, 49 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..6908d21 100644 --- a/week-3/2-mandatory/7-password-validator.js +++ b/week-3/2-mandatory/7-password-validator.js @@ -21,49 +21,65 @@ Expected Result: PasswordValidationResult= [false, false, false, false, true] */ +function validatePasswords(psw) { + var pswRegex = new RegExp( + "^(?=.*[a-z])(?=.*[A-Z])(?=.*[0-9])(?=.*[!.#$%])(?=.{5,})" + ); + var resultArr = []; + //let isFirstTime = true; + for (let i = 0; i < psw.length; i++) { + if (i === psw.indexOf(psw[i]) && pswRegex.test(psw[i])) { + //console.log(psw[i]) + //console.log(psw[i+i]) + resultArr.push(true); + } else { + //console.log(psw[i]) + resultArr.push(false); + } + } + console.log(resultArr); + return resultArr; +} -function validatePasswords(passwords) { +// function validatePasswords(passwords) { +// passwords.every(pswValidator) -} +// } /* ======= 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]) +);