From c6e39f948102328afa00c7aed9b5bbaee2724d35 Mon Sep 17 00:00:00 2001 From: LorenaCapraru <108892538+LorenaCapraru@users.noreply.github.com> Date: Thu, 24 Nov 2022 20:53:30 +0000 Subject: [PATCH 1/9] Initial commit till G --- exercises/B-hello-world/exercise.js | 5 ++++- exercises/C-variables/exercise.js | 4 +++- exercises/D-strings/exercise.js | 4 +++- exercises/E-strings-concatenation/exercise.js | 4 +++- exercises/F-strings-methods/exercise.js | 4 +++- exercises/F-strings-methods/exercise2.js | 4 ++-- exercises/G-numbers/exercise.js | 7 +++++++ 7 files changed, 25 insertions(+), 7 deletions(-) diff --git a/exercises/B-hello-world/exercise.js b/exercises/B-hello-world/exercise.js index b179ee953..184d21722 100644 --- a/exercises/B-hello-world/exercise.js +++ b/exercises/B-hello-world/exercise.js @@ -1 +1,4 @@ -console.log("Hello world"); +console.log("Hello world, I am learning Java Script"); +console.log(87); +//getting read of quote marks gives an error +//console.log(no) will print the number; diff --git a/exercises/C-variables/exercise.js b/exercises/C-variables/exercise.js index a6bbb9786..26a6983b6 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 = "Hello, JS is quite easy."; +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..0c805d72d 100644 --- a/exercises/D-strings/exercise.js +++ b/exercises/D-strings/exercise.js @@ -1,3 +1,5 @@ // Start by creating a variable `message` - +let message = "This is a string"; +let messageType = typeof message; console.log(message); +console.log(messageType); diff --git a/exercises/E-strings-concatenation/exercise.js b/exercises/E-strings-concatenation/exercise.js index 2cffa6a81..8893446d1 100644 --- a/exercises/E-strings-concatenation/exercise.js +++ b/exercises/E-strings-concatenation/exercise.js @@ -1,3 +1,5 @@ // Start by creating a variable `message` - +let fName = "Lorena"; +let greet = "Hi, my name is "; +let message = greet + fName; console.log(message); diff --git a/exercises/F-strings-methods/exercise.js b/exercises/F-strings-methods/exercise.js index 2cffa6a81..282949fe6 100644 --- a/exercises/F-strings-methods/exercise.js +++ b/exercises/F-strings-methods/exercise.js @@ -1,3 +1,5 @@ // Start by creating a variable `message` - +let myName = "Lorena"; +let message ="My name is "+myName+ " and my name is "+ myName.length+" characters long."; console.log(message); + diff --git a/exercises/F-strings-methods/exercise2.js b/exercises/F-strings-methods/exercise2.js index b4b46943d..da1ea746e 100644 --- a/exercises/F-strings-methods/exercise2.js +++ b/exercises/F-strings-methods/exercise2.js @@ -1,3 +1,3 @@ -const name = " Daniel "; - +const nameD = " Daniel "; +let message ="My name is " +nameD.trim() +" and my name is " + nameD.trim().length +" characters long."; console.log(message); diff --git a/exercises/G-numbers/exercise.js b/exercises/G-numbers/exercise.js index 49e7bc00b..e06608375 100644 --- a/exercises/G-numbers/exercise.js +++ b/exercises/G-numbers/exercise.js @@ -1 +1,8 @@ // Start by creating a variables `numberOfStudents` and `numberOfMentors` +let numberOfStudents = 50; +let numberOfMentors = 20; +let sum = 0; +sum = numberOfMentors + numberOfStudents; +console.log("Total number of students: " + numberOfStudents); +console.log("Total number of mentors: " + numberOfMentors); +console.log("Total number of students and mentors: " + sum); From 6f1bc539bf897b851d39bea95314ccc8108cf449 Mon Sep 17 00:00:00 2001 From: LorenaCapraru <108892538+LorenaCapraru@users.noreply.github.com> Date: Fri, 25 Nov 2022 11:46:57 +0000 Subject: [PATCH 2/9] new commit --- exercises/I-floats/exercise.js | 7 +++++++ exercises/J-functions/exercise.js | 1 + 2 files changed, 8 insertions(+) diff --git a/exercises/I-floats/exercise.js b/exercises/I-floats/exercise.js index a5bbcd852..48f61ed2e 100644 --- a/exercises/I-floats/exercise.js +++ b/exercises/I-floats/exercise.js @@ -1,2 +1,9 @@ var numberOfStudents = 15; var numberOfMentors = 8; +var sum = numberOfMentors + numberOfStudents; + +var studentsPercentage = (numberOfStudents / sum) * 100; +var mentorsPercentage = (numberOfMentors / sum) * 100; + +console.log(`Percentage students:${Math.round(studentsPercentage)}%`); +console.log(`Percentage mentors: ${Math.round(mentorsPercentage)}%`); diff --git a/exercises/J-functions/exercise.js b/exercises/J-functions/exercise.js index 0ae5850e5..0fc4c3655 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); From ee30240ae9bde0590005206b824f79127fc984e8 Mon Sep 17 00:00:00 2001 From: LorenaCapraru <108892538+LorenaCapraru@users.noreply.github.com> Date: Fri, 25 Nov 2022 12:25:08 +0000 Subject: [PATCH 3/9] Last commit --- exercises/J-functions/exercise2.js | 1 + exercises/K-functions-parameters/exercise.js | 3 ++- exercises/K-functions-parameters/exercise2.js | 4 +++- exercises/K-functions-parameters/exercise3.js | 3 +++ exercises/K-functions-parameters/exercise4.js | 6 ++++-- exercises/K-functions-parameters/exercise5.js | 4 +++- exercises/L-functions-nested/exercise.js | 11 +++++++++++ 7 files changed, 27 insertions(+), 5 deletions(-) diff --git a/exercises/J-functions/exercise2.js b/exercises/J-functions/exercise2.js index 82ef5e780..468d45596 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); diff --git a/exercises/K-functions-parameters/exercise.js b/exercises/K-functions-parameters/exercise.js index 8d5db5e69..9445a9692 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(number1, number2) { // Calculate the result of the function and return it + return number1 * number2; } // 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..f31171bce 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(number1, number2) { + return number1 / number2; +} var result = divide(3, 4); console.log(result); diff --git a/exercises/K-functions-parameters/exercise3.js b/exercises/K-functions-parameters/exercise3.js index 537e9f4ec..3341b2910 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(name) { + return "Hello, my name is " + name; +} var greeting = createGreeting("Daniel"); diff --git a/exercises/K-functions-parameters/exercise4.js b/exercises/K-functions-parameters/exercise4.js index 7ab44589e..e588aae12 100644 --- a/exercises/K-functions-parameters/exercise4.js +++ b/exercises/K-functions-parameters/exercise4.js @@ -1,5 +1,7 @@ // Declare your function first - +function sumNumbers(number1, number2) { + return number1 + number2; +} // Call the function and assign to a variable `sum` - +let sum = sumNumbers(13, 124); console.log(sum); diff --git a/exercises/K-functions-parameters/exercise5.js b/exercises/K-functions-parameters/exercise5.js index 7c5bcd605..524598c5c 100644 --- a/exercises/K-functions-parameters/exercise5.js +++ b/exercises/K-functions-parameters/exercise5.js @@ -1,5 +1,7 @@ // Declare your function here - +function createLongGreeting(name, age) { + return `Hello, my name is ${name} and I'm ${age} years.`; +} const greeting = createLongGreeting("Daniel", 30); console.log(greeting); diff --git a/exercises/L-functions-nested/exercise.js b/exercises/L-functions-nested/exercise.js index a5d377442..f0b57a11d 100644 --- a/exercises/L-functions-nested/exercise.js +++ b/exercises/L-functions-nested/exercise.js @@ -3,3 +3,14 @@ var mentor2 = "Irina"; var mentor3 = "Mimi"; var mentor4 = "Rob"; var mentor5 = "Yohannes"; + +function shoutyGreeting(mentorName) { + mentorName = mentorName.toUpperCase(); + return `HELLO ${mentorName}`; +} + +console.log(shoutyGreeting(mentor1)); +console.log(shoutyGreeting(mentor2)); +console.log(shoutyGreeting(mentor3)); +console.log(shoutyGreeting(mentor4)); +console.log(shoutyGreeting(mentor5)); From d0301da75b8f6881b929f50c8e97131068a7bcfa Mon Sep 17 00:00:00 2001 From: LorenaCapraru <108892538+LorenaCapraru@users.noreply.github.com> Date: Fri, 25 Nov 2022 12:41:51 +0000 Subject: [PATCH 4/9] Update exercise2.js --- exercises/F-strings-methods/exercise2.js | 1 + 1 file changed, 1 insertion(+) diff --git a/exercises/F-strings-methods/exercise2.js b/exercises/F-strings-methods/exercise2.js index da1ea746e..b782c7d92 100644 --- a/exercises/F-strings-methods/exercise2.js +++ b/exercises/F-strings-methods/exercise2.js @@ -1,3 +1,4 @@ const nameD = " Daniel "; let message ="My name is " +nameD.trim() +" and my name is " + nameD.trim().length +" characters long."; +//print the message console.log(message); From c9c00c48d1394bdccfb79300b9f2e106a7f44583 Mon Sep 17 00:00:00 2001 From: LorenaCapraru <108892538+LorenaCapraru@users.noreply.github.com> Date: Fri, 25 Nov 2022 12:47:41 +0000 Subject: [PATCH 5/9] delete mandatory --- mandatory/1-syntax-errors.js | 40 ------------------------- mandatory/2-logic-error.js | 51 ------------------------------- mandatory/3-function-output.js | 37 ----------------------- mandatory/4-tax.js | 55 ---------------------------------- 4 files changed, 183 deletions(-) delete mode 100644 mandatory/1-syntax-errors.js delete mode 100644 mandatory/2-logic-error.js delete mode 100644 mandatory/3-function-output.js delete mode 100644 mandatory/4-tax.js diff --git a/mandatory/1-syntax-errors.js b/mandatory/1-syntax-errors.js deleted file mode 100644 index a10cc9ac2..000000000 --- a/mandatory/1-syntax-errors.js +++ /dev/null @@ -1,40 +0,0 @@ -// There are syntax errors in this code - can you fix it to pass the tests? - -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 getTotal(a, b) { - total = a ++ b; - - return "The total is total"; -} - -/* -=================================================== -======= TESTS - DO NOT MODIFY BELOW THIS LINE ===== - -There are some Tests in this file that will help you work out if your code is working. - -To run the tests for just this one file, type `npm test -- --testPathPattern 1-syntax-errors` into your terminal -(Reminder: You must have run `npm install` one time before this will work!) - -=================================================== -*/ - -test("addNumbers adds numbers correctly", () => { - expect(addNumbers(3, 4, 6)).toEqual(13); -}); - -test("introduceMe function returns the correct string", () => { - expect(introduceMe("Sonjide", 27)).toEqual( - "Hello, my name is Sonjide and I am 27 years old" - ); -}); - -test("getTotal returns a string describing the total", () => { - expect(getTotal(23, 5)).toEqual("The total is 28"); -}); diff --git a/mandatory/2-logic-error.js b/mandatory/2-logic-error.js deleted file mode 100644 index 9cca7603b..000000000 --- a/mandatory/2-logic-error.js +++ /dev/null @@ -1,51 +0,0 @@ -// The syntax for this function is valid but it has an error, find it and fix it. - -function trimWord(word) { - return wordtrim(); -} - -function getStringLength(word) { - return "word".length(); -} - -function multiply(a, b, c) { - a * b * c; - return; -} - -/* -=================================================== -======= TESTS - DO NOT MODIFY BELOW THIS LINE ===== - -There are some Tests in this file that will help you work out if your code is working. - -To run the tests for just this one file, type `npm test -- --testPathPattern 2-logic-error` into your terminal -(Reminder: You must have run `npm install` one time before this will work!) -=================================================== -*/ - -test("trimWord trims leading and trailing whitespace", () => { - expect(trimWord(" CodeYourFuture ")).toEqual("CodeYourFuture"); -}); - -test("trimWord doesn't remove whitespace in the middle of the string", () => { - expect(trimWord(" CodeYourFuture teaches coding ")).toEqual( - "CodeYourFuture teaches coding" - ); -}); - -test("getStringLength returns the length of a word", () => { - expect(getStringLength("Turtles")).toEqual(7); -}); - -test("getStringLength returns the length of a sentence", () => { - expect(getStringLength("A wild sentence appeared!")).toEqual(25); -}); - -test("multiply multiplies numbers", () => { - expect(multiply(2, 3, 6)).toEqual(36); -}); - -test("multiply multiplies different numbers", () => { - expect(multiply(2, 3, 4)).toEqual(24); -}); diff --git a/mandatory/3-function-output.js b/mandatory/3-function-output.js deleted file mode 100644 index 5a953ba60..000000000 --- a/mandatory/3-function-output.js +++ /dev/null @@ -1,37 +0,0 @@ -// Add comments to explain what this function does. You're meant to use Google! -function getRandomNumber() { - return Math.random() * 10; -} - -// Add comments to explain what this function does. You're meant to use Google! -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. -} - -/* -=================================================== -======= TESTS - DO NOT MODIFY BELOW THIS LINE ===== - -There are some Tests in this file that will help you work out if your code is working. - -To run the tests for just this one file, type `npm test -- --testPathPattern 3-function-output` into your terminal -(Reminder: You must have run `npm install` one time before this will work!) -================================== -*/ - -test("concatenate example #1", () => { - expect(concatenate("code", "your", "future")).toEqual("code your future"); -}); - -test("concatenate example #2", () => { - expect(concatenate("I", "like", "pizza")).toEqual("I like pizza"); -}); - -test("concatenate doesn't only accept strings", () => { - expect(concatenate("I", "am", 13)).toEqual("I am 13"); -}); diff --git a/mandatory/4-tax.js b/mandatory/4-tax.js deleted file mode 100644 index ba77c7ae2..000000000 --- a/mandatory/4-tax.js +++ /dev/null @@ -1,55 +0,0 @@ -/* - SALES TAX - ========= - A business requires a program that calculates how much the price of a product is including sales tax - Sales tax is 20% of the price of the product. -*/ - -function calculateSalesTax() {} - -/* - CURRENCY FORMATTING - =================== - The business has informed you that prices must have 2 decimal places - They must also start with the currency symbol - Write a function that adds tax to a number, and then transforms the total into the format £0.00 - - Remember that the prices must include the sales tax (hint: you already wrote a function for this!) -*/ - -function addTaxAndFormatCurrency() {} - -/* -=================================================== -======= TESTS - DO NOT MODIFY BELOW THIS LINE ===== - -There are some Tests in this file that will help you work out if your code is working. - -To run the tests for just this one file, type `npm test -- --testPathPattern 4-tax` into your terminal -(Reminder: You must have run `npm install` one time before this will work!) -=================================================== -*/ - -test("calculateSalesTax for £15", () => { - expect(calculateSalesTax(15)).toEqual(18); -}); - -test("calculateSalesTax for £17.50", () => { - expect(calculateSalesTax(17.5)).toEqual(21); -}); - -test("calculateSalesTax for £34", () => { - expect(calculateSalesTax(34)).toEqual(40.8); -}); - -test("addTaxAndFormatCurrency for £15", () => { - expect(addTaxAndFormatCurrency(15)).toEqual("£18.00"); -}); - -test("addTaxAndFormatCurrency for £17.50", () => { - expect(addTaxAndFormatCurrency(17.5)).toEqual("£21.00"); -}); - -test("addTaxAndFormatCurrency for £34", () => { - expect(addTaxAndFormatCurrency(34)).toEqual("£40.80"); -}); From 3e5457f12370f2a72aa75897f3b22a79359a83df Mon Sep 17 00:00:00 2001 From: LorenaCapraru <108892538+LorenaCapraru@users.noreply.github.com> Date: Fri, 25 Nov 2022 12:52:55 +0000 Subject: [PATCH 6/9] Revert "delete mandatory" This reverts commit c9c00c48d1394bdccfb79300b9f2e106a7f44583. --- mandatory/1-syntax-errors.js | 40 +++++++++++++++++++++++++ mandatory/2-logic-error.js | 51 +++++++++++++++++++++++++++++++ mandatory/3-function-output.js | 37 +++++++++++++++++++++++ mandatory/4-tax.js | 55 ++++++++++++++++++++++++++++++++++ 4 files changed, 183 insertions(+) create mode 100644 mandatory/1-syntax-errors.js create mode 100644 mandatory/2-logic-error.js create mode 100644 mandatory/3-function-output.js create mode 100644 mandatory/4-tax.js diff --git a/mandatory/1-syntax-errors.js b/mandatory/1-syntax-errors.js new file mode 100644 index 000000000..a10cc9ac2 --- /dev/null +++ b/mandatory/1-syntax-errors.js @@ -0,0 +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; +} + +function introduceMe(name, age) + return "Hello, my name is " + name "and I am " age + "years old"; + +function getTotal(a, b) { + total = a ++ b; + + return "The total is total"; +} + +/* +=================================================== +======= TESTS - DO NOT MODIFY BELOW THIS LINE ===== + +There are some Tests in this file that will help you work out if your code is working. + +To run the tests for just this one file, type `npm test -- --testPathPattern 1-syntax-errors` into your terminal +(Reminder: You must have run `npm install` one time before this will work!) + +=================================================== +*/ + +test("addNumbers adds numbers correctly", () => { + expect(addNumbers(3, 4, 6)).toEqual(13); +}); + +test("introduceMe function returns the correct string", () => { + expect(introduceMe("Sonjide", 27)).toEqual( + "Hello, my name is Sonjide and I am 27 years old" + ); +}); + +test("getTotal returns a string describing the total", () => { + expect(getTotal(23, 5)).toEqual("The total is 28"); +}); diff --git a/mandatory/2-logic-error.js b/mandatory/2-logic-error.js new file mode 100644 index 000000000..9cca7603b --- /dev/null +++ b/mandatory/2-logic-error.js @@ -0,0 +1,51 @@ +// The syntax for this function is valid but it has an error, find it and fix it. + +function trimWord(word) { + return wordtrim(); +} + +function getStringLength(word) { + return "word".length(); +} + +function multiply(a, b, c) { + a * b * c; + return; +} + +/* +=================================================== +======= TESTS - DO NOT MODIFY BELOW THIS LINE ===== + +There are some Tests in this file that will help you work out if your code is working. + +To run the tests for just this one file, type `npm test -- --testPathPattern 2-logic-error` into your terminal +(Reminder: You must have run `npm install` one time before this will work!) +=================================================== +*/ + +test("trimWord trims leading and trailing whitespace", () => { + expect(trimWord(" CodeYourFuture ")).toEqual("CodeYourFuture"); +}); + +test("trimWord doesn't remove whitespace in the middle of the string", () => { + expect(trimWord(" CodeYourFuture teaches coding ")).toEqual( + "CodeYourFuture teaches coding" + ); +}); + +test("getStringLength returns the length of a word", () => { + expect(getStringLength("Turtles")).toEqual(7); +}); + +test("getStringLength returns the length of a sentence", () => { + expect(getStringLength("A wild sentence appeared!")).toEqual(25); +}); + +test("multiply multiplies numbers", () => { + expect(multiply(2, 3, 6)).toEqual(36); +}); + +test("multiply multiplies different numbers", () => { + expect(multiply(2, 3, 4)).toEqual(24); +}); diff --git a/mandatory/3-function-output.js b/mandatory/3-function-output.js new file mode 100644 index 000000000..5a953ba60 --- /dev/null +++ b/mandatory/3-function-output.js @@ -0,0 +1,37 @@ +// Add comments to explain what this function does. You're meant to use Google! +function getRandomNumber() { + return Math.random() * 10; +} + +// Add comments to explain what this function does. You're meant to use Google! +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. +} + +/* +=================================================== +======= TESTS - DO NOT MODIFY BELOW THIS LINE ===== + +There are some Tests in this file that will help you work out if your code is working. + +To run the tests for just this one file, type `npm test -- --testPathPattern 3-function-output` into your terminal +(Reminder: You must have run `npm install` one time before this will work!) +================================== +*/ + +test("concatenate example #1", () => { + expect(concatenate("code", "your", "future")).toEqual("code your future"); +}); + +test("concatenate example #2", () => { + expect(concatenate("I", "like", "pizza")).toEqual("I like pizza"); +}); + +test("concatenate doesn't only accept strings", () => { + expect(concatenate("I", "am", 13)).toEqual("I am 13"); +}); diff --git a/mandatory/4-tax.js b/mandatory/4-tax.js new file mode 100644 index 000000000..ba77c7ae2 --- /dev/null +++ b/mandatory/4-tax.js @@ -0,0 +1,55 @@ +/* + SALES TAX + ========= + A business requires a program that calculates how much the price of a product is including sales tax + Sales tax is 20% of the price of the product. +*/ + +function calculateSalesTax() {} + +/* + CURRENCY FORMATTING + =================== + The business has informed you that prices must have 2 decimal places + They must also start with the currency symbol + Write a function that adds tax to a number, and then transforms the total into the format £0.00 + + Remember that the prices must include the sales tax (hint: you already wrote a function for this!) +*/ + +function addTaxAndFormatCurrency() {} + +/* +=================================================== +======= TESTS - DO NOT MODIFY BELOW THIS LINE ===== + +There are some Tests in this file that will help you work out if your code is working. + +To run the tests for just this one file, type `npm test -- --testPathPattern 4-tax` into your terminal +(Reminder: You must have run `npm install` one time before this will work!) +=================================================== +*/ + +test("calculateSalesTax for £15", () => { + expect(calculateSalesTax(15)).toEqual(18); +}); + +test("calculateSalesTax for £17.50", () => { + expect(calculateSalesTax(17.5)).toEqual(21); +}); + +test("calculateSalesTax for £34", () => { + expect(calculateSalesTax(34)).toEqual(40.8); +}); + +test("addTaxAndFormatCurrency for £15", () => { + expect(addTaxAndFormatCurrency(15)).toEqual("£18.00"); +}); + +test("addTaxAndFormatCurrency for £17.50", () => { + expect(addTaxAndFormatCurrency(17.5)).toEqual("£21.00"); +}); + +test("addTaxAndFormatCurrency for £34", () => { + expect(addTaxAndFormatCurrency(34)).toEqual("£40.80"); +}); From f7f0afc73f17d429009a6d081f712aae7f88d7cc Mon Sep 17 00:00:00 2001 From: LorenaCapraru <108892538+LorenaCapraru@users.noreply.github.com> Date: Fri, 25 Nov 2022 12:59:00 +0000 Subject: [PATCH 7/9] first mendatory --- mandatory/1-syntax-errors.js | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/mandatory/1-syntax-errors.js b/mandatory/1-syntax-errors.js index a10cc9ac2..566b465d0 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 b3967ca1a9b2e0101df7eac9bec39e84d0ab46cd Mon Sep 17 00:00:00 2001 From: LorenaCapraru <108892538+LorenaCapraru@users.noreply.github.com> Date: Fri, 25 Nov 2022 13:03:51 +0000 Subject: [PATCH 8/9] Update 2-logic-error.js --- mandatory/2-logic-error.js | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/mandatory/2-logic-error.js b/mandatory/2-logic-error.js index 9cca7603b..242dfdba7 100644 --- a/mandatory/2-logic-error.js +++ b/mandatory/2-logic-error.js @@ -1,16 +1,17 @@ // 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(); + let length = word.length; + return length; } function multiply(a, b, c) { - a * b * c; - return; + let m = a * b * c; + return m; } /* From 6a7bb1d66aa92e66b1126eefe6e223362ec6b4c0 Mon Sep 17 00:00:00 2001 From: LorenaCapraru <108892538+LorenaCapraru@users.noreply.github.com> Date: Fri, 25 Nov 2022 13:36:09 +0000 Subject: [PATCH 9/9] last commit --- mandatory/3-function-output.js | 5 +++-- mandatory/4-tax.js | 10 ++++++++-- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/mandatory/3-function-output.js b/mandatory/3-function-output.js index 5a953ba60..823f0c9ff 100644 --- a/mandatory/3-function-output.js +++ b/mandatory/3-function-output.js @@ -1,15 +1,16 @@ -// Add comments to explain what this function does. You're meant to use Google! +// it generates a random number using Math.random() library and returns the number multiplied with 10 function getRandomNumber() { return Math.random() * 10; } -// Add comments to explain what this function does. You're meant to use Google! +// it concatenates 2 different strings using concat() method function combine2Words(word1, word2) { return word1.concat(word2); } function concatenate(firstWord, secondWord, thirdWord) { // Write the body of this function to concatenate three words together. + return firstWord.concat(" ", secondWord.concat(" ", thirdWord)); // Look at the test case below to understand what this function is expected to return. } diff --git a/mandatory/4-tax.js b/mandatory/4-tax.js index ba77c7ae2..037f854f5 100644 --- a/mandatory/4-tax.js +++ b/mandatory/4-tax.js @@ -5,7 +5,10 @@ Sales tax is 20% of the price of the product. */ -function calculateSalesTax() {} +function calculateSalesTax(number) { + let priceOfTheProduct = number * 1.2; + return priceOfTheProduct; +} /* CURRENCY FORMATTING @@ -17,7 +20,10 @@ function calculateSalesTax() {} Remember that the prices must include the sales tax (hint: you already wrote a function for this!) */ -function addTaxAndFormatCurrency() {} +function addTaxAndFormatCurrency(no) { + no = calculateSalesTax(no); + return `£${no.toFixed(2)}`; +} /* ===================================================