From 1d24419ba2b6621650974d47926867280a0e500e Mon Sep 17 00:00:00 2001 From: ShimenAfshar <106038638+ShimenAfshar@users.noreply.github.com> Date: Wed, 24 Aug 2022 21:27:00 +0100 Subject: [PATCH 1/5] exercises a, b, c --- exercises/B-hello-world/README.md | 2 +- exercises/B-hello-world/exercise.js | 8 ++++++++ exercises/C-variables/exercise.js | 4 +++- exercises/D-strings/exercise.js | 3 +++ mandatory/1-syntax-errors.js | 13 +++++++------ 5 files changed, 22 insertions(+), 8 deletions(-) diff --git a/exercises/B-hello-world/README.md b/exercises/B-hello-world/README.md index 27282c4af..5dd683670 100644 --- a/exercises/B-hello-world/README.md +++ b/exercises/B-hello-world/README.md @@ -12,7 +12,7 @@ Inside of `exercise.js` there's a line of code that will print "Hello world!". ### 2. Experiment -- Try to `console.log()` something different. For example, 'Hello World. I just started learning JavaScript!'. +- Try to `console.log()` something different. For example, `cd exercises/B-hello-world`). - Try to console.log() several things at once. - What happens when you get rid of the quote marks? - What happens when you console.log() just a number without quotes? diff --git a/exercises/B-hello-world/exercise.js b/exercises/B-hello-world/exercise.js index b179ee953..5c84d24e1 100644 --- a/exercises/B-hello-world/exercise.js +++ b/exercises/B-hello-world/exercise.js @@ -1 +1,9 @@ console.log("Hello world"); +console.log("week5"); +console.log("code your future"); + + + + + + diff --git a/exercises/C-variables/exercise.js b/exercises/C-variables/exercise.js index a6bbb9786..d9fc713be 100644 --- a/exercises/C-variables/exercise.js +++ b/exercises/C-variables/exercise.js @@ -1,3 +1,5 @@ // Start by creating a variable `greeting` - +var greeting = "Helo World" +console.log(greeting); +console.log(greeting); console.log(greeting); diff --git a/exercises/D-strings/exercise.js b/exercises/D-strings/exercise.js index 2cffa6a81..d4b27fec0 100644 --- a/exercises/D-strings/exercise.js +++ b/exercises/D-strings/exercise.js @@ -1,3 +1,6 @@ // Start by creating a variable `message` +let message = "This is a string"; +let messageType = message; console.log(message); +console.log(typeof message); diff --git a/mandatory/1-syntax-errors.js b/mandatory/1-syntax-errors.js index a10cc9ac2..ef560ed5d 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; + total = a + b; + + return "The total is " + total; - return "The total is total"; } /* From 8655abeccf3801cadd4f90a4c49e0220df55e8e6 Mon Sep 17 00:00:00 2001 From: ShimenAfshar <106038638+ShimenAfshar@users.noreply.github.com> Date: Wed, 24 Aug 2022 21:36:41 +0100 Subject: [PATCH 2/5] exercises e,f --- exercises/D-strings/exercise.js | 7 +++---- exercises/E-strings-concatenation/exercise.js | 3 +++ exercises/F-strings-methods/exercise.js | 3 +++ exercises/F-strings-methods/exercise2.js | 6 ++++-- 4 files changed, 13 insertions(+), 6 deletions(-) diff --git a/exercises/D-strings/exercise.js b/exercises/D-strings/exercise.js index d4b27fec0..e110c1478 100644 --- a/exercises/D-strings/exercise.js +++ b/exercises/D-strings/exercise.js @@ -1,6 +1,5 @@ // Start by creating a variable `message` - -let message = "This is a string"; -let messageType = message; +var message = "This is string" +var messageType = typeof message; console.log(message); -console.log(typeof message); +console.log(messageType); diff --git a/exercises/E-strings-concatenation/exercise.js b/exercises/E-strings-concatenation/exercise.js index 2cffa6a81..dacb36acf 100644 --- a/exercises/E-strings-concatenation/exercise.js +++ b/exercises/E-strings-concatenation/exercise.js @@ -1,3 +1,6 @@ // Start by creating a variable `message` +var greeting = "hello, My name is "; +var myName = "Shimen"; +var message = greeting + myName; console.log(message); diff --git a/exercises/F-strings-methods/exercise.js b/exercises/F-strings-methods/exercise.js index 2cffa6a81..fece7f87d 100644 --- a/exercises/F-strings-methods/exercise.js +++ b/exercises/F-strings-methods/exercise.js @@ -1,3 +1,6 @@ // Start by creating a variable `message` +const name = "Shimen"; +const nameLength = name.length; +const message = "My name is " + name + " and the length of my name " + nameLength; console.log(message); diff --git a/exercises/F-strings-methods/exercise2.js b/exercises/F-strings-methods/exercise2.js index b4b46943d..0c06ccf8b 100644 --- a/exercises/F-strings-methods/exercise2.js +++ b/exercises/F-strings-methods/exercise2.js @@ -1,3 +1,5 @@ const name = " Daniel "; - -console.log(message); +const convertetName = name.trim(); +const nameLength = name.length; +const message = "My name is " + convertetName + " and the length of my name " + nameLength; +console.log(message); \ No newline at end of file From 0cc65e7146fd11f4b8afe15d293bfca88abf094b Mon Sep 17 00:00:00 2001 From: ShimenAfshar <106038638+ShimenAfshar@users.noreply.github.com> Date: Wed, 24 Aug 2022 21:42:03 +0100 Subject: [PATCH 3/5] exercises d, g , i --- 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..f4ad19720 100644 --- a/exercises/G-numbers/exercise.js +++ b/exercises/G-numbers/exercise.js @@ -1 +1,7 @@ // Start by creating a variables `numberOfStudents` and `numberOfMentors` +var numberOfStudents = 15; +var numberOfMentors = 8; +let total = numberOfMentors + numberOfStudents; + +console.log("Percentage students: "+ Math.round(numberOfStudents/total*100) + "%"); +console.log("Percentage mentors: "+ Math.round(numberOfMentors/total*100) + "%"); \ No newline at end of file From c71fe3e8e19ab3f4aa3d6e9f2686189fa62077a8 Mon Sep 17 00:00:00 2001 From: ShimenAfshar <106038638+ShimenAfshar@users.noreply.github.com> Date: Wed, 24 Aug 2022 21:48:13 +0100 Subject: [PATCH 4/5] exercises j, k, l --- exercises/J-functions/exercise.js | 5 +++++ exercises/J-functions/exercise2.js | 3 ++- exercises/K-functions-parameters/exercise.js | 5 +++-- exercises/K-functions-parameters/exercise2.js | 6 ++++-- exercises/K-functions-parameters/exercise3.js | 8 +++++--- exercises/K-functions-parameters/exercise4.js | 10 ++++++---- exercises/K-functions-parameters/exercise5.js | 6 ++++-- exercises/L-functions-nested/exercise.js | 14 ++++++++++++++ 8 files changed, 43 insertions(+), 14 deletions(-) diff --git a/exercises/J-functions/exercise.js b/exercises/J-functions/exercise.js index 0ae5850e5..39a771dad 100644 --- a/exercises/J-functions/exercise.js +++ b/exercises/J-functions/exercise.js @@ -1,7 +1,12 @@ function halve(number) { // complete the function here + return number/2; } var result = halve(12); +var result2 = halve(28); +var result3 = halve(64); console.log(result); +console.log(result2); +console.log(result3); \ No newline at end of file diff --git a/exercises/J-functions/exercise2.js b/exercises/J-functions/exercise2.js index 82ef5e780..1398f8ecd 100644 --- a/exercises/J-functions/exercise2.js +++ b/exercises/J-functions/exercise2.js @@ -1,7 +1,8 @@ function triple(number) { // complete function here + return number*3; } var result = triple(12); -console.log(result); +console.log(result); \ No newline at end of file diff --git a/exercises/K-functions-parameters/exercise.js b/exercises/K-functions-parameters/exercise.js index 8d5db5e69..375922387 100644 --- a/exercises/K-functions-parameters/exercise.js +++ b/exercises/K-functions-parameters/exercise.js @@ -1,9 +1,10 @@ // 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` var result = multiply(3, 4); -console.log(result); +console.log(result); \ No newline at end of file diff --git a/exercises/K-functions-parameters/exercise2.js b/exercises/K-functions-parameters/exercise2.js index db7a8904b..a1f628462 100644 --- a/exercises/K-functions-parameters/exercise2.js +++ b/exercises/K-functions-parameters/exercise2.js @@ -1,5 +1,7 @@ // Declare your function first - +function divide(a, b){ + return a/b; +} var result = divide(3, 4); -console.log(result); +console.log(result); \ No newline at end of file diff --git a/exercises/K-functions-parameters/exercise3.js b/exercises/K-functions-parameters/exercise3.js index 537e9f4ec..a611a288f 100644 --- a/exercises/K-functions-parameters/exercise3.js +++ b/exercises/K-functions-parameters/exercise3.js @@ -1,5 +1,7 @@ // Write your function here +function createGreeting(yourName){ + return "Hello, my name is " + yourName; +} +var greeting = createGreeting("Hayat"); -var greeting = createGreeting("Daniel"); - -console.log(greeting); +console.log(greeting); \ No newline at end of file diff --git a/exercises/K-functions-parameters/exercise4.js b/exercises/K-functions-parameters/exercise4.js index 7ab44589e..a611a288f 100644 --- a/exercises/K-functions-parameters/exercise4.js +++ b/exercises/K-functions-parameters/exercise4.js @@ -1,5 +1,7 @@ -// Declare your function first +// Write your function here +function createGreeting(yourName){ + return "Hello, my name is " + yourName; +} +var greeting = createGreeting("Hayat"); -// Call the function and assign to a variable `sum` - -console.log(sum); +console.log(greeting); \ No newline at end of file diff --git a/exercises/K-functions-parameters/exercise5.js b/exercises/K-functions-parameters/exercise5.js index 7c5bcd605..c295dfc63 100644 --- a/exercises/K-functions-parameters/exercise5.js +++ b/exercises/K-functions-parameters/exercise5.js @@ -1,5 +1,7 @@ // Declare your function here - -const greeting = createLongGreeting("Daniel", 30); +function createLongGreeting(yourName, age){ + return "Hello, my name is " +yourName + " and I'm " + age + " years old" +} +const greeting = createLongGreeting("Hayat", 35); console.log(greeting); diff --git a/exercises/L-functions-nested/exercise.js b/exercises/L-functions-nested/exercise.js index a5d377442..1713c7308 100644 --- a/exercises/L-functions-nested/exercise.js +++ b/exercises/L-functions-nested/exercise.js @@ -1,5 +1,19 @@ + +function nameInUpper(mentorName){ + return mentorName.toUpperCase(); +} + +function shoutyGreeting(name){ + return "HELLO " + nameInUpper(name); +} var mentor1 = "Daniel"; var mentor2 = "Irina"; var mentor3 = "Mimi"; var mentor4 = "Rob"; var mentor5 = "Yohannes"; + +console.log(shoutyGreeting(mentor1)); +console.log(shoutyGreeting(mentor2)); +console.log(shoutyGreeting(mentor3)); +console.log(shoutyGreeting(mentor4)); +console.log(shoutyGreeting(mentor5)); \ No newline at end of file From 3eccf09f8977f1d9c877d56d6f73379da0b83281 Mon Sep 17 00:00:00 2001 From: ShimenAfshar <106038638+ShimenAfshar@users.noreply.github.com> Date: Thu, 25 Aug 2022 20:31:21 +0100 Subject: [PATCH 5/5] mandatory(syntax-logic) --- mandatory/2-logic-error.js | 9 ++++----- mandatory/3-function-output.js | 6 ++---- mandatory/4-tax.js | 13 +++++++++++-- 3 files changed, 17 insertions(+), 11 deletions(-) diff --git a/mandatory/2-logic-error.js b/mandatory/2-logic-error.js index 9cca7603b..c8db880e3 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 getStringLength(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 5a953ba60..eeed62c06 100644 --- a/mandatory/3-function-output.js +++ b/mandatory/3-function-output.js @@ -3,16 +3,14 @@ function getRandomNumber() { return Math.random() * 10; } -// Add comments to explain what this function does. You're meant to use Google! +// Join two strings function combine2Words(word1, word2) { return word1.concat(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.concat(" ", secondWord, " ", thirdWord); } - /* =================================================== ======= TESTS - DO NOT MODIFY BELOW THIS LINE ===== diff --git a/mandatory/4-tax.js b/mandatory/4-tax.js index ba77c7ae2..0c575fe22 100644 --- a/mandatory/4-tax.js +++ b/mandatory/4-tax.js @@ -5,8 +5,13 @@ Sales tax is 20% of the price of the product. */ -function calculateSalesTax() {} +const TAX_RATE = 0.2; + +function calculateSalesTax(price) { + let tax = price * TAX_RATE; + return price + tax; +} /* 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 addTaxAndFormatCurrency() {} + +function addTaxAndFormatCurrency(price) { + let fullPrice = calculateSalesTax(price).toFixed(2); + return "£" + fullPrice; +} /* ===================================================