From 57a4c54dfe2bcefc0ee28e818d3fb8d742f5966d Mon Sep 17 00:00:00 2001 From: tenzyns <86624297+tenzyns@users.noreply.github.com> Date: Sun, 8 Aug 2021 16:26:33 +0100 Subject: [PATCH 01/19] Update 1-syntax-errors.js Corrected syntax errors --- 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..8a817bf5a 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 c51cd900f46573f98718a3bb565ebb10787b9901 Mon Sep 17 00:00:00 2001 From: tenzyns <86624297+tenzyns@users.noreply.github.com> Date: Sun, 8 Aug 2021 16:48:35 +0100 Subject: [PATCH 02/19] Update 2-logic-error.js Logic error fixed --- 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..0e0002e69 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(); + var num = word.length; + return num; } function multiply(a, b, c) { - a * b * c; - return; + return a * b * c; + } /* From 64fe7f4f0921839dc617f6c212713b33513b000d Mon Sep 17 00:00:00 2001 From: tenzyns <86624297+tenzyns@users.noreply.github.com> Date: Sun, 8 Aug 2021 17:10:20 +0100 Subject: [PATCH 03/19] Update 3-function-output.js Added comments and corrected the 3rd function --- mandatory/3-function-output.js | 3 +++ 1 file changed, 3 insertions(+) diff --git a/mandatory/3-function-output.js b/mandatory/3-function-output.js index 5a953ba60..77392b62f 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! +// this function generates a random number between 0 and 9 including floating numbers. function getRandomNumber() { return Math.random() * 10; } // Add comments to explain what this function does. You're meant to use Google! +//this function outputs the strings word1 and word2 concatenated 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; } /* From 428d570c70d95afa36d09bc19d49af198b504151 Mon Sep 17 00:00:00 2001 From: tenzyns <86624297+tenzyns@users.noreply.github.com> Date: Sun, 8 Aug 2021 17:47:01 +0100 Subject: [PATCH 04/19] Update 4-tax.js Sales tax function created --- mandatory/4-tax.js | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/mandatory/4-tax.js b/mandatory/4-tax.js index ba77c7ae2..487fe1ef9 100644 --- a/mandatory/4-tax.js +++ b/mandatory/4-tax.js @@ -4,8 +4,11 @@ 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. */ +var price; -function calculateSalesTax() {} +function calculateSalesTax(price) { +return 1.20 * price; +} /* CURRENCY FORMATTING @@ -17,7 +20,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) { + netPrice = calculateSalesTax(price).toFixed(2); + return `£${netPrice}`; + +} /* =================================================== From 5b51685df35c999350801f68d9f8b9bb4bf55759 Mon Sep 17 00:00:00 2001 From: tenzyns <86624297+tenzyns@users.noreply.github.com> Date: Sun, 8 Aug 2021 22:08:12 +0100 Subject: [PATCH 05/19] Update exercise.js Exercise B completed --- exercises/B-hello-world/exercise.js | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/exercises/B-hello-world/exercise.js b/exercises/B-hello-world/exercise.js index b179ee953..4f4bb6f24 100644 --- a/exercises/B-hello-world/exercise.js +++ b/exercises/B-hello-world/exercise.js @@ -1 +1,5 @@ console.log("Hello world"); +console.log("Hello world, I just started learning javascript!") +console.log("Tashi Delek!") +console.log(2938); + From cfdca74a1ed64d3915453bae43fc6730a7a1cf40 Mon Sep 17 00:00:00 2001 From: tenzyns <86624297+tenzyns@users.noreply.github.com> Date: Sun, 8 Aug 2021 22:24:03 +0100 Subject: [PATCH 06/19] Update exercise.js completed exercise C --- exercises/C-variables/exercise.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/exercises/C-variables/exercise.js b/exercises/C-variables/exercise.js index a6bbb9786..cb888c0ee 100644 --- a/exercises/C-variables/exercise.js +++ b/exercises/C-variables/exercise.js @@ -1,3 +1,5 @@ // Start by creating a variable `greeting` - +let greeting = "Tashi Delek!" +console.log(greeting); +console.log(greeting); console.log(greeting); From 797da8592fa910dffa0826f10b0ed6fe0ac366d4 Mon Sep 17 00:00:00 2001 From: tenzyns <86624297+tenzyns@users.noreply.github.com> Date: Sun, 8 Aug 2021 22:35:49 +0100 Subject: [PATCH 07/19] Update exercise.js Added variable and typeof command --- exercises/D-strings/exercise.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/exercises/D-strings/exercise.js b/exercises/D-strings/exercise.js index 2cffa6a81..726e4f1c0 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 = "Save the planet earth!" console.log(message); +let messageType = typeof message; +console.log(messageType); \ No newline at end of file From fc4497ad2aa8705f04f67cd8ac77d838f02be632 Mon Sep 17 00:00:00 2001 From: tenzyns <86624297+tenzyns@users.noreply.github.com> Date: Sun, 8 Aug 2021 22:42:47 +0100 Subject: [PATCH 08/19] Update exercise.js Greetings concatenation added. --- exercises/E-strings-concatenation/exercise.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/exercises/E-strings-concatenation/exercise.js b/exercises/E-strings-concatenation/exercise.js index 2cffa6a81..a2f0dcdda 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` - -console.log(message); +let message = "Hello my name is "; +let myName = "Tenzynski"; +let greeting = message + myName; +console.log(greeting); From cfcba32f73a8bf2fc04819e9039e3af1e9324210 Mon Sep 17 00:00:00 2001 From: tenzyns <86624297+tenzyns@users.noreply.github.com> Date: Sun, 8 Aug 2021 22:53:25 +0100 Subject: [PATCH 09/19] Update exercise.js My name's character length is printed. --- exercises/F-strings-methods/exercise.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/exercises/F-strings-methods/exercise.js b/exercises/F-strings-methods/exercise.js index 2cffa6a81..b405e941a 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 = "Tenzynski"; +let nameLength = myName.length; +let message = `My name is ${myName} and my name is ${nameLength} characters long.` console.log(message); From 6bc4aad2b4f0286d942150470d580f8104a87fee Mon Sep 17 00:00:00 2001 From: tenzyns <86624297+tenzyns@users.noreply.github.com> Date: Sun, 8 Aug 2021 23:03:52 +0100 Subject: [PATCH 10/19] Update exercise2.js used string trim function and character length. --- exercises/F-strings-methods/exercise2.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/exercises/F-strings-methods/exercise2.js b/exercises/F-strings-methods/exercise2.js index b4b46943d..dbdcc6e12 100644 --- a/exercises/F-strings-methods/exercise2.js +++ b/exercises/F-strings-methods/exercise2.js @@ -1,3 +1,5 @@ -const name = " Daniel "; - +const myName = " Daniel "; +const nameTrim = myName.trim(); +const nameLength = nameTrim.length; +const message = `My name is ${nameTrim} and my name is ${nameLength} characters long.`; console.log(message); From fbd9593aa446e101024d77d4f4569d7d282b2bc4 Mon Sep 17 00:00:00 2001 From: tenzyns <86624297+tenzyns@users.noreply.github.com> Date: Mon, 9 Aug 2021 15:43:48 +0100 Subject: [PATCH 11/19] Update exercise.js G-numbers exercise completed --- exercises/G-numbers/exercise.js | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/exercises/G-numbers/exercise.js b/exercises/G-numbers/exercise.js index 49e7bc00b..4c115e2d5 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 = 13; +let numberOfMentors = 8; +totalNum = numberOfMentors + numberOfStudents; +console.log(`The total number of students and mentors is ${totalNum}.`) \ No newline at end of file From b932e4c434f2afee14fc3f26664955dda1af6c1b Mon Sep 17 00:00:00 2001 From: tenzyns <86624297+tenzyns@users.noreply.github.com> Date: Mon, 9 Aug 2021 15:56:04 +0100 Subject: [PATCH 12/19] Update exercise.js Floats exercise completed --- exercises/I-floats/exercise.js | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/exercises/I-floats/exercise.js b/exercises/I-floats/exercise.js index a5bbcd852..b46c7dcd4 100644 --- a/exercises/I-floats/exercise.js +++ b/exercises/I-floats/exercise.js @@ -1,2 +1,6 @@ var numberOfStudents = 15; var numberOfMentors = 8; +percentageStudent = Math.round(numberOfStudents *100/(numberOfStudents + numberOfMentors)); +percentageMentor = Math.round(numberOfMentors*100/(numberOfMentors + numberOfStudents)); +console.log(`Percentage of students: ${percentageStudent}%`); +console.log(`Percentage of mentors: ${percentageMentor}%`); From 21b381440e51055c44c0eb04647a0be74975c197 Mon Sep 17 00:00:00 2001 From: tenzyns <86624297+tenzyns@users.noreply.github.com> Date: Mon, 9 Aug 2021 16:08:43 +0100 Subject: [PATCH 13/19] Function exercises updated 2 exercises in J-function folder completed. Added function that halves a number and another function that triples a number. --- exercises/J-functions/exercise.js | 6 +++++- exercises/J-functions/exercise2.js | 4 +++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/exercises/J-functions/exercise.js b/exercises/J-functions/exercise.js index 0ae5850e5..c4e63dd4f 100644 --- a/exercises/J-functions/exercise.js +++ b/exercises/J-functions/exercise.js @@ -1,7 +1,11 @@ function halve(number) { // complete the function here + return number/2; } var result = halve(12); - +let answer = halve(34); +let output = halve(98); console.log(result); +console.log(answer); +console.log(output); \ No newline at end of file diff --git a/exercises/J-functions/exercise2.js b/exercises/J-functions/exercise2.js index 82ef5e780..dda41781b 100644 --- a/exercises/J-functions/exercise2.js +++ b/exercises/J-functions/exercise2.js @@ -1,7 +1,9 @@ function triple(number) { // complete function here + return number * 3; } var result = triple(12); - +let answer = triple(49); console.log(result); +console.log(answer); From 104448424f91aa87ed168e8a625cb1a7c562d71c Mon Sep 17 00:00:00 2001 From: tenzyns <86624297+tenzyns@users.noreply.github.com> Date: Mon, 9 Aug 2021 16:34:54 +0100 Subject: [PATCH 14/19] Function parameters updated Completed exercises on function parameters. --- exercises/K-functions-parameters/exercise.js | 3 ++- exercises/K-functions-parameters/exercise2.js | 3 +++ exercises/K-functions-parameters/exercise3.js | 4 +++- exercises/K-functions-parameters/exercise4.js | 6 ++++-- exercises/K-functions-parameters/exercise5.js | 4 +++- 5 files changed, 15 insertions(+), 5 deletions(-) diff --git a/exercises/K-functions-parameters/exercise.js b/exercises/K-functions-parameters/exercise.js index 8d5db5e69..a4eed9d76 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(num1, num2) { // Calculate the result of the function and return it + return num1 * num2; } // 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..0ebe3dc66 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(num1, numb2){ + return num1 / numb2; +} var result = divide(3, 4); diff --git a/exercises/K-functions-parameters/exercise3.js b/exercises/K-functions-parameters/exercise3.js index 537e9f4ec..c7c3d13de 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}. How are you?` +} var greeting = createGreeting("Daniel"); console.log(greeting); diff --git a/exercises/K-functions-parameters/exercise4.js b/exercises/K-functions-parameters/exercise4.js index 7ab44589e..e8e5fbcf7 100644 --- a/exercises/K-functions-parameters/exercise4.js +++ b/exercises/K-functions-parameters/exercise4.js @@ -1,5 +1,7 @@ // Declare your function first - +function addTwoNum(num1, num2){ + return num1 + num2; +} // Call the function and assign to a variable `sum` - +let sum = addTwoNum(13, 124); console.log(sum); diff --git a/exercises/K-functions-parameters/exercise5.js b/exercises/K-functions-parameters/exercise5.js index 7c5bcd605..1196b15b4 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(myName, age){ + return `Hello! my name is ${myName} and I am ${age} years old.` +} const greeting = createLongGreeting("Daniel", 30); console.log(greeting); From 692bb05f7273f7f982219629df11039250b73214 Mon Sep 17 00:00:00 2001 From: tenzyns <86624297+tenzyns@users.noreply.github.com> Date: Mon, 9 Aug 2021 21:09:14 +0100 Subject: [PATCH 15/19] Nested function update Shouty greeting completed --- exercises/L-functions-nested/exercise.js | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/exercises/L-functions-nested/exercise.js b/exercises/L-functions-nested/exercise.js index a5d377442..c7f70ecc4 100644 --- a/exercises/L-functions-nested/exercise.js +++ b/exercises/L-functions-nested/exercise.js @@ -3,3 +3,16 @@ var mentor2 = "Irina"; var mentor3 = "Mimi"; var mentor4 = "Rob"; var mentor5 = "Yohannes"; + +function getUpperCase(yourName){ + return yourName.toUpperCase(); +} + +function shoutyGreeting(yourName){ + return `HELLO ${getUpperCase(yourName)}`; +} +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 2d66c1f151f25a9c41cae68e0b85b72e7d2bb8ea Mon Sep 17 00:00:00 2001 From: tenzyns <86624297+tenzyns@users.noreply.github.com> Date: Mon, 9 Aug 2021 22:20:15 +0100 Subject: [PATCH 16/19] Update 1-currency-conversion.js currency conversion test passed --- extra/1-currency-conversion.js | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/extra/1-currency-conversion.js b/extra/1-currency-conversion.js index d82e59480..f05af2fe3 100644 --- a/extra/1-currency-conversion.js +++ b/extra/1-currency-conversion.js @@ -5,7 +5,9 @@ Write a function that converts a price to USD (exchange rate is 1.4 $ to £) */ -function convertToUSD() {} +function convertToUSD(price) { + return price * 1.4; +} /* CURRENCY CONVERSION @@ -15,7 +17,10 @@ function convertToUSD() {} They have also decided that they should add a 1% fee to all foreign transactions, which means you only convert 99% of the £ to BRL. */ -function convertToBRL() {} +function convertToBRL(cost) { + let real = 0.99 * cost * 5.7; + return +(Math.round(real + "e+2") + "e-2"); +} /* ======= TESTS - DO NOT MODIFY ===== There are some Tests in this file that will help you work out if your code is working. From 63bbe768090215284d1e8c6c10dcdb9d55b958c9 Mon Sep 17 00:00:00 2001 From: tenzyns <86624297+tenzyns@users.noreply.github.com> Date: Tue, 10 Aug 2021 21:33:13 +0100 Subject: [PATCH 17/19] Update 2-piping.js Completed nested functions --- extra/2-piping.js | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/extra/2-piping.js b/extra/2-piping.js index 9c8ebc76a..299b3077d 100644 --- a/extra/2-piping.js +++ b/extra/2-piping.js @@ -16,26 +16,34 @@ the final result to the variable goodCode */ -function add() { +function add(startingValue, lastValue) { + return startingValue + lastValue; } -function multiply() { +function multiply(startingValue, lastValue) { + return startingValue * lastValue; } -function format() { +function format(startingValue) { + return `£${startingValue}`; } const startingValue = 2; - +const lastValue = 10; +add(2, 10); multiply(add(2, 10), 2); format(multiply(add(2, 10), 2)); // Why can this code be seen as bad practice? Comment your answer. -let badCode = +// These codes are not properly indented and each statement needs to be on a separate line +let badCode = format(multiply(add(2, 10), 2)); /* BETTER PRACTICE */ - -let goodCode = +// each statement of codes should be on a separate line and neatly indented. + add(2, 10); + multiply(add(2, 10), 2); + format(multiply(add(2, 10), 2)); +let goodCode = format(multiply(add(2, 10), 2)); /* ======= TESTS - DO NOT MODIFY ===== There are some Tests in this file that will help you work out if your code is working. From bc2edce56cc89165601a1af1c26016a9bddba4b9 Mon Sep 17 00:00:00 2001 From: tenzyns <86624297+tenzyns@users.noreply.github.com> Date: Tue, 7 Sep 2021 22:42:33 +0100 Subject: [PATCH 18/19] Update 3-magic-8-ball.js Magic ball solved. --- extra/3-magic-8-ball.js | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/extra/3-magic-8-ball.js b/extra/3-magic-8-ball.js index f3adbefa5..6d881179e 100644 --- a/extra/3-magic-8-ball.js +++ b/extra/3-magic-8-ball.js @@ -45,8 +45,19 @@ // This should log "The ball has shaken!" // and return the answer. +const magicAnswers = ["It is certain.", "It is decidedly so.", + "Without a doubt.", "Yes - definitely", "You may rely on it.", + "As I see it, yes.", "Most likely.", "Outlook good.", "Yes.", "Signs point to yes.", + "Reply hazy, try again.", "Ask again later.", "Better not tell you now.", + "Cannot predict now.", "Concentrate and ask again.", + "Don't count on us.", "My reply is no.", "My sources say no.", + "Outlook not so good.", "Very doubtful." ]; function shakeBall() { //Write your code in here + let index = Math.floor(Math.random() * magicAnswers.length) + let response = magicAnswers[index]; + console.log("The ball has shaken!"); + return response; } /* @@ -60,6 +71,20 @@ function shakeBall() { */ function checkAnswer(answer) { //Write your code in here + let i = magicAnswers.indexOf(answer); + if (i <= 4) { + return "very positive"; + } + if (i > 4 && i < 10) { + return "positive"; + } + if (i > 9 && i < 15){ + return "negative"; + } + if (i > 14 && i < 20){ + return "very negative"; + } + } /* From 0924a6f5e766820d73b40a21b30da5c6e0d14175 Mon Sep 17 00:00:00 2001 From: tenzyns <86624297+tenzyns@users.noreply.github.com> Date: Tue, 7 Sep 2021 22:59:37 +0100 Subject: [PATCH 19/19] Update 3-magic-8-ball.js Updated if statement for function checkAnswer(). --- extra/3-magic-8-ball.js | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/extra/3-magic-8-ball.js b/extra/3-magic-8-ball.js index 6d881179e..f7ba818ed 100644 --- a/extra/3-magic-8-ball.js +++ b/extra/3-magic-8-ball.js @@ -75,15 +75,13 @@ function checkAnswer(answer) { if (i <= 4) { return "very positive"; } - if (i > 4 && i < 10) { + if (i < 10) { return "positive"; } - if (i > 9 && i < 15){ + if (i < 15){ return "negative"; } - if (i > 14 && i < 20){ return "very negative"; - } }