From 11f2dc905b95d933bef0d79f33ebb353c2fcd6a5 Mon Sep 17 00:00:00 2001 From: Aashiq Abrahams Date: Thu, 18 Mar 2021 20:14:37 +0200 Subject: [PATCH 01/12] B-hello-world completed --- exercises/B-hello-world/exercise.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/exercises/B-hello-world/exercise.js b/exercises/B-hello-world/exercise.js index b179ee953..75f713334 100644 --- a/exercises/B-hello-world/exercise.js +++ b/exercises/B-hello-world/exercise.js @@ -1 +1,3 @@ console.log("Hello world"); +console.log("Hello World. I just started learning JavaScript!"); +console.log(2); From cdec892a6afe0cb869a393bc70834f058cae27b8 Mon Sep 17 00:00:00 2001 From: Aashiq Abrahams Date: Thu, 18 Mar 2021 20:21:15 +0200 Subject: [PATCH 02/12] c-variables completed --- exercises/C-variables/exercise.js | 3 +++ 1 file changed, 3 insertions(+) diff --git a/exercises/C-variables/exercise.js b/exercises/C-variables/exercise.js index a6bbb9786..ef7e25bb9 100644 --- a/exercises/C-variables/exercise.js +++ b/exercises/C-variables/exercise.js @@ -1,3 +1,6 @@ // Start by creating a variable `greeting` +const greeting = "Hello World"; console.log(greeting); +console.log(greeting); +console.log(greeting); From 93b709dbe4cc901ebb9d6c90dcccd0be8636aeb8 Mon Sep 17 00:00:00 2001 From: Aashiq Abrahams Date: Thu, 18 Mar 2021 20:25:05 +0200 Subject: [PATCH 03/12] d-strings completed --- exercises/D-strings/exercise.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/exercises/D-strings/exercise.js b/exercises/D-strings/exercise.js index 2cffa6a81..abadfec8d 100644 --- a/exercises/D-strings/exercise.js +++ b/exercises/D-strings/exercise.js @@ -1,3 +1,5 @@ // Start by creating a variable `message` +const message = "This is a String"; console.log(message); +console.log(typeof message); From 484971ccc85ec5f21fffa90578a6b0fca9ca7800 Mon Sep 17 00:00:00 2001 From: Aashiq Abrahams Date: Thu, 18 Mar 2021 20:29:14 +0200 Subject: [PATCH 04/12] e-strings-concatenation completed --- exercises/E-strings-concatenation/exercise.js | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/exercises/E-strings-concatenation/exercise.js b/exercises/E-strings-concatenation/exercise.js index 2cffa6a81..5cfbf34a9 100644 --- a/exercises/E-strings-concatenation/exercise.js +++ b/exercises/E-strings-concatenation/exercise.js @@ -1,3 +1,7 @@ // Start by creating a variable `message` +let greetingStart = "Hello, my name is "; +let name = "Aashiq" -console.log(message); +let greeting = greetingStart + name; + +console.log(greeting); From 624329b26c136aa6d3f26c63c5b16eb7c1eb4536 Mon Sep 17 00:00:00 2001 From: Aashiq Abrahams Date: Thu, 18 Mar 2021 20:35:10 +0200 Subject: [PATCH 05/12] f-strings-methods completed --- exercises/F-strings-methods/exercise.js | 3 ++- exercises/F-strings-methods/exercise2.js | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/exercises/F-strings-methods/exercise.js b/exercises/F-strings-methods/exercise.js index 2cffa6a81..535ca0308 100644 --- a/exercises/F-strings-methods/exercise.js +++ b/exercises/F-strings-methods/exercise.js @@ -1,3 +1,4 @@ // Start by creating a variable `message` +const name = "Aashiq"; -console.log(message); +console.log("My name is " + name + " and my name is " + name.length + " characters long"); diff --git a/exercises/F-strings-methods/exercise2.js b/exercises/F-strings-methods/exercise2.js index b4b46943d..2fa3aa87e 100644 --- a/exercises/F-strings-methods/exercise2.js +++ b/exercises/F-strings-methods/exercise2.js @@ -1,3 +1,3 @@ const name = " Daniel "; -console.log(message); +console.log("My name is " + name.trim() + " and my name is " + name.trim().length + " characters long"); From 7b1c49b27f48fb2e066b1939badc22d794b3faa0 Mon Sep 17 00:00:00 2001 From: Aashiq Abrahams Date: Thu, 18 Mar 2021 21:15:30 +0200 Subject: [PATCH 06/12] g-numbers completed --- exercises/G-numbers/exercise.js | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/exercises/G-numbers/exercise.js b/exercises/G-numbers/exercise.js index 49e7bc00b..186a6faa6 100644 --- a/exercises/G-numbers/exercise.js +++ b/exercises/G-numbers/exercise.js @@ -1 +1,7 @@ // Start by creating a variables `numberOfStudents` and `numberOfMentors` +const numberOfStudents = 15; +const numberOfMentors = 8; + +console.log("Number of students: " + numberOfStudents); +console.log("Number of mentors: " + numberOfMentors); +console.log("Total number of students and mentors: " + (numberOfMentors + numberOfStudents)); \ No newline at end of file From f2a951a7b2b9d5d7e5bd76130407eacbe957314e Mon Sep 17 00:00:00 2001 From: Aashiq Abrahams Date: Thu, 18 Mar 2021 21:23:59 +0200 Subject: [PATCH 07/12] i-floats completed --- exercises/I-floats/exercise.js | 3 +++ 1 file changed, 3 insertions(+) diff --git a/exercises/I-floats/exercise.js b/exercises/I-floats/exercise.js index a5bbcd852..fea86c38b 100644 --- a/exercises/I-floats/exercise.js +++ b/exercises/I-floats/exercise.js @@ -1,2 +1,5 @@ var numberOfStudents = 15; var numberOfMentors = 8; + +console.log("Percentage students: " + Math.round(numberOfStudents/(numberOfStudents + numberOfMentors)*100)+"%"); +console.log("Percentage mentors: " + Math.round(numberOfMentors/(numberOfStudents + numberOfMentors)*100)+"%"); From d907da81ea5f8267a0bfd0c126d4a83f33b01542 Mon Sep 17 00:00:00 2001 From: Aashiq Abrahams Date: Thu, 18 Mar 2021 21:26:37 +0200 Subject: [PATCH 08/12] j-functions completed --- exercises/J-functions/exercise.js | 1 + exercises/J-functions/exercise2.js | 1 + 2 files changed, 2 insertions(+) diff --git a/exercises/J-functions/exercise.js b/exercises/J-functions/exercise.js index 0ae5850e5..e9ba2f0ef 100644 --- a/exercises/J-functions/exercise.js +++ b/exercises/J-functions/exercise.js @@ -1,5 +1,6 @@ function halve(number) { // complete the function here + return number/2; } var result = halve(12); diff --git a/exercises/J-functions/exercise2.js b/exercises/J-functions/exercise2.js index 82ef5e780..6d216ffc6 100644 --- a/exercises/J-functions/exercise2.js +++ b/exercises/J-functions/exercise2.js @@ -1,5 +1,6 @@ function triple(number) { // complete function here + return number*3; } var result = triple(12); From 036f1bc1c601d03b5746383e7772d826dc8cb275 Mon Sep 17 00:00:00 2001 From: Aashiq Abrahams Date: Thu, 18 Mar 2021 21:34:36 +0200 Subject: [PATCH 09/12] k-functions competed --- exercises/K-functions-parameters/exercise.js | 3 ++- exercises/K-functions-parameters/exercise2.js | 3 +++ exercises/K-functions-parameters/exercise3.js | 3 +++ exercises/K-functions-parameters/exercise4.js | 4 ++++ exercises/K-functions-parameters/exercise5.js | 3 +++ 5 files changed, 15 insertions(+), 1 deletion(-) diff --git a/exercises/K-functions-parameters/exercise.js b/exercises/K-functions-parameters/exercise.js index 8d5db5e69..46e0bb26a 100644 --- a/exercises/K-functions-parameters/exercise.js +++ b/exercises/K-functions-parameters/exercise.js @@ -1,6 +1,7 @@ // Complete the function so that it takes input parameters -function multiply() { +function multiply(a, b) { // Calculate the result of the function and return it + return a*b; } // Assign the result of calling the function the variable `result` diff --git a/exercises/K-functions-parameters/exercise2.js b/exercises/K-functions-parameters/exercise2.js index db7a8904b..02a698a36 100644 --- a/exercises/K-functions-parameters/exercise2.js +++ b/exercises/K-functions-parameters/exercise2.js @@ -1,4 +1,7 @@ // Declare your function first +function divide(a, b) { + return a/b; +} var result = divide(3, 4); diff --git a/exercises/K-functions-parameters/exercise3.js b/exercises/K-functions-parameters/exercise3.js index 537e9f4ec..6de0f0538 100644 --- a/exercises/K-functions-parameters/exercise3.js +++ b/exercises/K-functions-parameters/exercise3.js @@ -1,4 +1,7 @@ // Write your function here +function createGreeting(greet) { + return "Hello, my name is " + greet; +} var greeting = createGreeting("Daniel"); diff --git a/exercises/K-functions-parameters/exercise4.js b/exercises/K-functions-parameters/exercise4.js index 7ab44589e..ebecbf75c 100644 --- a/exercises/K-functions-parameters/exercise4.js +++ b/exercises/K-functions-parameters/exercise4.js @@ -1,5 +1,9 @@ // Declare your function first +function addition(a, b) { + return a + b; +} // Call the function and assign to a variable `sum` +let sum = addition(13, 124); console.log(sum); diff --git a/exercises/K-functions-parameters/exercise5.js b/exercises/K-functions-parameters/exercise5.js index 7c5bcd605..0ca4da254 100644 --- a/exercises/K-functions-parameters/exercise5.js +++ b/exercises/K-functions-parameters/exercise5.js @@ -1,4 +1,7 @@ // 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 ee5c784c384d957b7626bc4a93d732e09ccddc8d Mon Sep 17 00:00:00 2001 From: Aashiq Abrahams Date: Thu, 18 Mar 2021 21:48:37 +0200 Subject: [PATCH 10/12] l-functions completed --- exercises/L-functions-nested/exercise.js | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/exercises/L-functions-nested/exercise.js b/exercises/L-functions-nested/exercise.js index a5d377442..54059d6d6 100644 --- a/exercises/L-functions-nested/exercise.js +++ b/exercises/L-functions-nested/exercise.js @@ -3,3 +3,17 @@ var mentor2 = "Irina"; var mentor3 = "Mimi"; var mentor4 = "Rob"; var mentor5 = "Yohannes"; + +function shoutName(name) { + return name.toUpperCase(); +} + +function shoutGreeting(mentor) { + return "HELLO " + shoutName(mentor); +} + +console.log(shoutGreeting(mentor1)); +console.log(shoutGreeting(mentor2)); +console.log(shoutGreeting(mentor3)); +console.log(shoutGreeting(mentor4)); +console.log(shoutGreeting(mentor5)); From df2c5c8ac97fe97d478efef49efc68f1b3f59704 Mon Sep 17 00:00:00 2001 From: Aashiq Abrahams Date: Fri, 19 Mar 2021 21:13:37 +0200 Subject: [PATCH 11/12] mandatory completed --- mandatory/1-syntax-errors.js | 11 ++++++----- mandatory/2-logic-error.js | 7 +++---- mandatory/3-function-output.js | 7 +++++-- mandatory/4-tax.js | 9 +++++++-- 4 files changed, 21 insertions(+), 13 deletions(-) diff --git a/mandatory/1-syntax-errors.js b/mandatory/1-syntax-errors.js index 0a21afd1b..ba30dff91 100644 --- a/mandatory/1-syntax-errors.js +++ b/mandatory/1-syntax-errors.js @@ -1,16 +1,17 @@ // 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 getTotal(a, b) { - total = a ++ b; + const total = a + b; - return "The total is total" + return 'The total is ${total}'; } /* diff --git a/mandatory/2-logic-error.js b/mandatory/2-logic-error.js index 3c578ad87..5f52c1294 100644 --- a/mandatory/2-logic-error.js +++ b/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 word.trim(); } function getWordLength(word) { - return "word".length(); + return word.length; } function multiply(a, b, c) { - a * b * c; - return; + return a * b * c; } /* diff --git a/mandatory/3-function-output.js b/mandatory/3-function-output.js index c2498486f..bf741f611 100644 --- a/mandatory/3-function-output.js +++ b/mandatory/3-function-output.js @@ -1,9 +1,11 @@ // Add comments to explain what this function does. You're meant to use Google! -function getRandomNumber() { - return Math.random() * 10; +// This function returns a random number >= 0 and < 10 +function getNumber() { + return Math.random() * 10; } // Add comments to explain what this function does. You're meant to use Google! +// This function returns the two input parameters concatenated (i.e. the second one following the first) function combine2Words(word1, word2) { return word1.concat(word2); } @@ -11,6 +13,7 @@ function combine2Words(word1, word2) { 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 this function is expected to return. + return `${firstWord} ${secondWord} ${thirdWord}`; } /* diff --git a/mandatory/4-tax.js b/mandatory/4-tax.js index e9d23dc90..03ba500ac 100644 --- a/mandatory/4-tax.js +++ b/mandatory/4-tax.js @@ -5,7 +5,9 @@ Sales tax is 20% of the price of the product. */ -function calculateSalesTax() {} +function calculateSalesTax(price) { + return price += price * 0.2; +} /* CURRENCY FORMATTING @@ -17,7 +19,10 @@ function calculateSalesTax() {} Remember that the prices must include the sales tax (hint: you already wrote a function for this!) */ -function addTaxAndFormatCurrency() {} +function addTaxAndFormatCurrency(price) { + price = calculateSalesTax(price); + return `£${price.toFixed(2)}` +} /* =================================================== From d56e1eb77dede2504a68d5ef818226b5f0bf24fa Mon Sep 17 00:00:00 2001 From: Aashiq Abrahams Date: Mon, 29 Mar 2021 20:56:06 +0200 Subject: [PATCH 12/12] Fixed error -with- return "The total is" + total; --- README.md | 2 +- mandatory/1-syntax-errors.js | 4 ++-- mandatory/3-function-output.js | 8 +++++--- mandatory/4-tax.js | 5 +++-- 4 files changed, 11 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index 5833a402f..2e6079265 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ Like learning a musical instrument, programming requires daily practise. -The exercises are split into three folders: `exercises`, `mandatory` and `extra`. All homework in the `exercise` and `mandatory` section **must** be completed for homework by the following lesson. +The exercises are split into three folders: `exercises`, `mandatory` and `extra`. All homework in the `exercise` and `mandatory` section **must** be completed for homework by the following lesson. The `extra` folder contains exercises that you can complete to challenge yourself, but are not required for the following lesson. diff --git a/mandatory/1-syntax-errors.js b/mandatory/1-syntax-errors.js index ba30dff91..6128bbf34 100644 --- a/mandatory/1-syntax-errors.js +++ b/mandatory/1-syntax-errors.js @@ -5,13 +5,13 @@ function addNumbers(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 getTotal(a, b) { const total = a + b; - return 'The total is ${total}'; + return "The total is " + total; } /* diff --git a/mandatory/3-function-output.js b/mandatory/3-function-output.js index bf741f611..940d5d550 100644 --- a/mandatory/3-function-output.js +++ b/mandatory/3-function-output.js @@ -1,13 +1,13 @@ // Add comments to explain what this function does. You're meant to use Google! // This function returns a random number >= 0 and < 10 function getNumber() { - return Math.random() * 10; + return Math.random() * 10; // returns the number entered multiplied by a random integer from 0 to 9 } // Add comments to explain what this function does. You're meant to use Google! // This function returns the two input parameters concatenated (i.e. the second one following the first) -function combine2Words(word1, word2) { - return word1.concat(word2); +function combine2Words(w1, w2) { + return word1.concat(w2); // concatenates w1 and w2 without white space } function concatenate(firstWord, secondWord, thirdWord) { @@ -16,6 +16,8 @@ function concatenate(firstWord, secondWord, thirdWord) { return `${firstWord} ${secondWord} ${thirdWord}`; } +console.log(concatenate("Code","Your","Future")); + /* =================================================== ======= TESTS - DO NOT MODIFY BELOW THIS LINE ===== diff --git a/mandatory/4-tax.js b/mandatory/4-tax.js index 03ba500ac..fff137662 100644 --- a/mandatory/4-tax.js +++ b/mandatory/4-tax.js @@ -5,9 +5,10 @@ Sales tax is 20% of the price of the product. */ -function calculateSalesTax(price) { - return price += price * 0.2; +function calculateSalesTax(productPrice) { + return productPrice * 1.2; } +console.log(calculateSalesTax(15)); /* CURRENCY FORMATTING