From 31f2728c3802ca50680f894ceeaa1164034f225b Mon Sep 17 00:00:00 2001 From: Getson47 <103142147+Getson47@users.noreply.github.com> Date: Fri, 1 Jul 2022 22:04:19 +0200 Subject: [PATCH] ZA --- exercises/B-hello-world/exercise.js | 4 +++- exercises/D-strings/exercise.js | 4 +++- exercises/E-strings-concatenation/exercise.js | 6 +++++- exercises/F-strings-methods/exercise.js | 5 ++++- exercises/F-strings-methods/exercise2.js | 3 ++- exercises/G-numbers/exercise.js | 4 ++++ exercises/J-functions/exercise.js | 2 ++ exercises/J-functions/exercise2.js | 2 ++ mandatory/1-syntax-errors.js | 20 ++++++++++++------- mandatory/2-logic-error.js | 13 ++++++++---- mandatory/3-function-output.js | 17 +++++++++++++--- mandatory/4-tax.js | 12 +++++++++-- 12 files changed, 71 insertions(+), 21 deletions(-) diff --git a/exercises/B-hello-world/exercise.js b/exercises/B-hello-world/exercise.js index b179ee953..69ccedd94 100644 --- a/exercises/B-hello-world/exercise.js +++ b/exercises/B-hello-world/exercise.js @@ -1 +1,3 @@ -console.log("Hello world"); +let greeting= ("Hello world") +console.log("greeting"); + diff --git a/exercises/D-strings/exercise.js b/exercises/D-strings/exercise.js index 2cffa6a81..217a077ea 100644 --- a/exercises/D-strings/exercise.js +++ b/exercises/D-strings/exercise.js @@ -1,3 +1,5 @@ // Start by creating a variable `message` -console.log(message); +let myName="This is a string"; + +console.log(myName); diff --git a/exercises/E-strings-concatenation/exercise.js b/exercises/E-strings-concatenation/exercise.js index 2cffa6a81..d77b83329 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` -console.log(message); +let greetingStart = "Hello"; +let name = "My name is Getson"; +let greeting = " greetingStart + name"; + +console.log(greeting); \ No newline at end of file diff --git a/exercises/F-strings-methods/exercise.js b/exercises/F-strings-methods/exercise.js index 2cffa6a81..9588be800 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` -console.log(message); +let name ="Getson"; +let nameLength = "name.length"; + +console.log(nameLength); diff --git a/exercises/F-strings-methods/exercise2.js b/exercises/F-strings-methods/exercise2.js index b4b46943d..c53020beb 100644 --- a/exercises/F-strings-methods/exercise2.js +++ b/exercises/F-strings-methods/exercise2.js @@ -1,3 +1,4 @@ const name = " Daniel "; +const nameTrim = "name.trim"; -console.log(message); +console.log(nameTrim); diff --git a/exercises/G-numbers/exercise.js b/exercises/G-numbers/exercise.js index 49e7bc00b..a1e798e8a 100644 --- a/exercises/G-numbers/exercise.js +++ b/exercises/G-numbers/exercise.js @@ -1 +1,5 @@ // Start by creating a variables `numberOfStudents` and `numberOfMentors` +let numberOfStudents = 15; +let numberOfMentors = 8; + +console.log(numberOfStudents + numberOfMentors); \ No newline at end of file diff --git a/exercises/J-functions/exercise.js b/exercises/J-functions/exercise.js index 0ae5850e5..e523dc9ea 100644 --- a/exercises/J-functions/exercise.js +++ b/exercises/J-functions/exercise.js @@ -1,5 +1,7 @@ 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..1949bb03f 100644 --- a/exercises/J-functions/exercise2.js +++ b/exercises/J-functions/exercise2.js @@ -1,5 +1,7 @@ function triple(number) { // complete function here + + return number * 3; } var result = triple(12); diff --git a/mandatory/1-syntax-errors.js b/mandatory/1-syntax-errors.js index a10cc9ac2..31715e596 100644 --- a/mandatory/1-syntax-errors.js +++ b/mandatory/1-syntax-errors.js @@ -1,16 +1,22 @@ // 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"; + const result = addNumbers(4,6,4); + +function introduceMe(name, age){ + return "Hello, my name is " + name + " and I am " + age + " years old"; + +} + +const intro = introduceMe( "John", 20); function getTotal(a, b) { - total = a ++ b; + total = a + b; - return "The total is total"; + return "The total is 28"; } /* @@ -18,8 +24,8 @@ function getTotal(a, b) { ======= 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 +npm test -- --testPathPattern 1-syntax-errors +To run the tests for just this one file, type `` into your terminal (Reminder: You must have run `npm install` one time before this will work!) =================================================== diff --git a/mandatory/2-logic-error.js b/mandatory/2-logic-error.js index 9cca7603b..758c17ba6 100644 --- a/mandatory/2-logic-error.js +++ b/mandatory/2-logic-error.js @@ -1,17 +1,22 @@ // 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(); } +let result = "CodeyourFuture"; +trimWord(result); + function getStringLength(word) { - return "word".length(); + return word.length; } function multiply(a, b, c) { - a * b * c; - return; + return a * b * c; + } +let answer = 2 * 3 * 6; +multiply(answer); /* =================================================== diff --git a/mandatory/3-function-output.js b/mandatory/3-function-output.js index 5a953ba60..4cab77e86 100644 --- a/mandatory/3-function-output.js +++ b/mandatory/3-function-output.js @@ -1,17 +1,28 @@ // Add comments to explain what this function does. You're meant to use Google! function getRandomNumber() { return Math.random() * 10; -} +}// The Math.random() function returns a floating-point, pseudo-random number in the range 0 to less than 1 (inclusive of 0, but not 1) with approximately +// uniform distribution over that range — which you can then scale to your desired range. +// The implementation selects the initial seed to the random number generation algorithm; // Add comments to explain what this function does. You're meant to use Google! function combine2Words(word1, word2) { return word1.concat(word2); -} +}// The concat() method is used to merge two or more arrays + 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; + } + + let text = "Code + your + Future"; + concatenate(text); + + + + /* =================================================== diff --git a/mandatory/4-tax.js b/mandatory/4-tax.js index ba77c7ae2..2c3bdf743 100644 --- a/mandatory/4-tax.js +++ b/mandatory/4-tax.js @@ -5,7 +5,13 @@ Sales tax is 20% of the price of the product. */ -function calculateSalesTax() {} +function calculateSalesTax(a,b) { + return a * b; + + +} +let num = 15* 0.2; +calculateSalesTax (num); /* CURRENCY FORMATTING @@ -17,7 +23,9 @@ function calculateSalesTax() {} Remember that the prices must include the sales tax (hint: you already wrote a function for this!) */ -function addTaxAndFormatCurrency() {} +function addTaxAndFormatCurrency(tax) { +return +} /* ===================================================