From a58ecdc35bc3337bf38b16de1c360053b13e0bf5 Mon Sep 17 00:00:00 2001 From: tony-dev-wm Date: Mon, 21 Nov 2022 18:40:10 +0000 Subject: [PATCH 01/14] 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..e270488d8 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 8f5ddb112acc48bbd5ced17990cf0df4ca9ab96f Mon Sep 17 00:00:00 2001 From: tony-dev-wm Date: Mon, 21 Nov 2022 18:45:36 +0000 Subject: [PATCH 02/14] logic errors --- mandatory/2-logic-error.js | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/mandatory/2-logic-error.js b/mandatory/2-logic-error.js index 9cca7603b..e9cf04a3f 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; } /* From 093f6af3a5e8ef07cdf623a801da616cf77b248d Mon Sep 17 00:00:00 2001 From: tony-dev-wm Date: Mon, 21 Nov 2022 18:52:43 +0000 Subject: [PATCH 03/14] functions output --- mandatory/3-function-output.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/mandatory/3-function-output.js b/mandatory/3-function-output.js index 5a953ba60..30445a59b 100644 --- a/mandatory/3-function-output.js +++ b/mandatory/3-function-output.js @@ -1,9 +1,9 @@ -// Add comments to explain what this function does. You're meant to use Google! +// Add comments to explain what this function does. You're meant to use Google! Math random gets numbers between 0-1. to get an integer we would need to use Math.floor as well as the function below can return decimals. function getRandomNumber() { return Math.random() * 10; } -// Add comments to explain what this function does. You're meant to use Google! +// Add comments to explain what this function does. You're meant to use Google! it will combine the two words without any space and return them. function combine2Words(word1, word2) { return word1.concat(word2); } @@ -11,6 +11,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.concat(" ", secondWord, " ", thirdWord); } /* From a7fa40b12af6aa495eef9a9e31c6a70424beed90 Mon Sep 17 00:00:00 2001 From: tony-dev-wm Date: Mon, 21 Nov 2022 19:17:25 +0000 Subject: [PATCH 04/14] tax --- mandatory/4-tax.js | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/mandatory/4-tax.js b/mandatory/4-tax.js index ba77c7ae2..5d4843945 100644 --- a/mandatory/4-tax.js +++ b/mandatory/4-tax.js @@ -5,7 +5,11 @@ Sales tax is 20% of the price of the product. */ -function calculateSalesTax() {} +function calculateSalesTax(product) { + let incTax=product*1.2; + return incTax; + +} /* CURRENCY FORMATTING @@ -17,7 +21,11 @@ function calculateSalesTax() {} Remember that the prices must include the sales tax (hint: you already wrote a function for this!) */ -function addTaxAndFormatCurrency() {} +function addTaxAndFormatCurrency(currency) { +let first=calculateSalesTax(currency); +let second=first.toFixed(2); +return `£${second}`; +} /* =================================================== From f30028a3d117f04756169e27df87257c027b0c26 Mon Sep 17 00:00:00 2001 From: tony-dev-wm Date: Mon, 21 Nov 2022 19:47:27 +0000 Subject: [PATCH 05/14] exercises --- exercises/B-hello-world/exercise.js | 4 ++++ exercises/C-variables/exercise.js | 4 +++- exercises/D-strings/exercise.js | 4 +++- exercises/E-strings-concatenation/exercise.js | 4 +++- 4 files changed, 13 insertions(+), 3 deletions(-) diff --git a/exercises/B-hello-world/exercise.js b/exercises/B-hello-world/exercise.js index b179ee953..84ed1806a 100644 --- a/exercises/B-hello-world/exercise.js +++ b/exercises/B-hello-world/exercise.js @@ -1 +1,5 @@ console.log("Hello world"); +console.log("finally understood how to use terminal"); +console.log("gives error without quotes"); +console.log(100); +console.log("it gets the number") \ No newline at end of file diff --git a/exercises/C-variables/exercise.js b/exercises/C-variables/exercise.js index a6bbb9786..1dd1a4fbe 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="Hello 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..997a05816 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="Tony was here"; +let type=typeof message; console.log(message); +console.log(type); diff --git a/exercises/E-strings-concatenation/exercise.js b/exercises/E-strings-concatenation/exercise.js index 2cffa6a81..a7a7b6fb5 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 first="My name is" +let second=" King Tony" +let message=first + second console.log(message); From ece1901cb160cd5ff999e6c46903ad6a5bd76536 Mon Sep 17 00:00:00 2001 From: tony-dev-wm Date: Mon, 21 Nov 2022 20:10:32 +0000 Subject: [PATCH 06/14] exercises --- exercises/F-strings-methods/exercise.js | 3 ++- exercises/F-strings-methods/exercise2.js | 2 +- exercises/G-numbers/exercise.js | 4 ++++ 3 files changed, 7 insertions(+), 2 deletions(-) diff --git a/exercises/F-strings-methods/exercise.js b/exercises/F-strings-methods/exercise.js index 2cffa6a81..324c64443 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` - +var name = "tony"; +var message = name.length; console.log(message); diff --git a/exercises/F-strings-methods/exercise2.js b/exercises/F-strings-methods/exercise2.js index b4b46943d..46f8f00ef 100644 --- a/exercises/F-strings-methods/exercise2.js +++ b/exercises/F-strings-methods/exercise2.js @@ -1,3 +1,3 @@ const name = " Daniel "; - +let message=name.toLowerCase(); console.log(message); diff --git a/exercises/G-numbers/exercise.js b/exercises/G-numbers/exercise.js index 49e7bc00b..afce3974a 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 numOfStudents=15; +let numOfMentors=8; +let abs=numOfMentors+numOfStudents; +console.log("the total number of sty and men are:" + abs) \ No newline at end of file From 5f6040a4de166114594ec0c5566344137bfd3682 Mon Sep 17 00:00:00 2001 From: tony-dev-wm Date: Mon, 21 Nov 2022 20:20:46 +0000 Subject: [PATCH 07/14] exercises --- exercises/I-floats/exercise.js | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/exercises/I-floats/exercise.js b/exercises/I-floats/exercise.js index a5bbcd852..ca8080dbe 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 men=Math.round((numberOfMentors/sum)*100); +var stu=Math.round((numberOfStudents/sum)*100); +console.log(men); +console.log(stu); + From 6747c600ea82f931c6044f6417f2e3fd1124dfd2 Mon Sep 17 00:00:00 2001 From: tony-dev-wm Date: Tue, 22 Nov 2022 19:44:32 +0000 Subject: [PATCH 08/14] work in progress --- exercises/J-functions/exercise.js | 1 + 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 | 4 +++- exercises/K-functions-parameters/exercise4.js | 5 ++++- extra/1-currency-conversion.js | 9 +++++++-- 7 files changed, 21 insertions(+), 6 deletions(-) diff --git a/exercises/J-functions/exercise.js b/exercises/J-functions/exercise.js index 0ae5850e5..27ad56963 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..f410dd3f9 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*number*number } var result = triple(12); diff --git a/exercises/K-functions-parameters/exercise.js b/exercises/K-functions-parameters/exercise.js index 8d5db5e69..568ebe7da 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..873046400 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); diff --git a/exercises/K-functions-parameters/exercise3.js b/exercises/K-functions-parameters/exercise3.js index 537e9f4ec..70009687c 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(name){ + return ("Nice to meet you " + name) +} 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..25560007a 100644 --- a/exercises/K-functions-parameters/exercise4.js +++ b/exercises/K-functions-parameters/exercise4.js @@ -1,5 +1,8 @@ // Declare your function first // Call the function and assign to a variable `sum` - +function summed(a,b){ + return a+b +}; +let sum =summed(13,24) console.log(sum); diff --git a/extra/1-currency-conversion.js b/extra/1-currency-conversion.js index 75b3c6aab..a54bad0ed 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(gbp) { + return Number((gbp*1.4).toFixed(2)); +} /* 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(brazil) { + let ninetyNine=(brazil*99)/100; + return Number((ninetyNine*5.7).toFixed(2)); +} /* ======= TESTS - DO NOT MODIFY ===== There are some Tests in this file that will help you work out if your code is working. From 2eafb34520192ff91272de4ebbf96d4d20181808 Mon Sep 17 00:00:00 2001 From: tony-dev-wm Date: Wed, 23 Nov 2022 10:42:20 +0000 Subject: [PATCH 09/14] exercise --- extra/2-piping.js | 14 ++++++++------ extra/3-magic-8-ball.js | 3 ++- 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/extra/2-piping.js b/extra/2-piping.js index b4f8c4c1b..aea68587d 100644 --- a/extra/2-piping.js +++ b/extra/2-piping.js @@ -16,26 +16,28 @@ the final result to the variable goodCode */ -function add() { +function add(a,b) { + return a+b; } -function multiply() { - +function multiply(a,b) { +return a*b; } -function format() { +function format(c) { + return `£${c}`; } const startingValue = 2; // Why can this code be seen as bad practice? Comment your answer. -let badCode = +let badCode = format((startingValue+10)*2); /* BETTER PRACTICE */ -let goodCode = +let goodCode = format((startingValue+10)*2); /* ======= TESTS - DO NOT MODIFY ===== There are some Tests in this file that will help you work out if your code is working. diff --git a/extra/3-magic-8-ball.js b/extra/3-magic-8-ball.js index 46f65f928..43b7fcb4e 100644 --- a/extra/3-magic-8-ball.js +++ b/extra/3-magic-8-ball.js @@ -47,8 +47,9 @@ // and return the answer. function shakeBall() { //Write your code in here + return ("The ball has shaken!"); } - +console.log(shakeBall) /* This function should say whether the answer it is given is - very positive From 5f8ab4facfc3133915807a97b786ee737c06a493 Mon Sep 17 00:00:00 2001 From: tony-dev-wm Date: Thu, 24 Nov 2022 14:02:08 +0000 Subject: [PATCH 10/14] updated --- extra/3-magic-8-ball.js | 75 +++++++++++++++++++++++++++++++++++++++-- 1 file changed, 72 insertions(+), 3 deletions(-) diff --git a/extra/3-magic-8-ball.js b/extra/3-magic-8-ball.js index 43b7fcb4e..b4360d011 100644 --- a/extra/3-magic-8-ball.js +++ b/extra/3-magic-8-ball.js @@ -42,14 +42,65 @@ Outlook not so good. Very doubtful. */ +const { toBeOneOf } = require("jest-extended"); + +const veryPositiveAnswers = [ + "It is certain.", + "It is decidedly so.", + "Without a doubt.", + "Yes - definitely.", + "You may rely on it.", +]; + +const positiveAnswers = [ + " As I see it, yes.", + "Most likely.", + " Outlook good.", + "Yes.", + " Signs point to yes.", +]; + +const negativeAnswers = [ + "Reply hazy, try again.", + "Ask again later.", + "Better not tell you now.", + "Cannot predict now.", + "Concentrate and ask again.", +]; +const veryNegativeAnswers = [ + "Don't count on it.", + "My reply is no.", + "My sources say no.", + "Outlook not so good.", + "Very doubtful.", +]; + +const listsOfAnswers = [ + veryPositiveAnswers, + positiveAnswers, + negativeAnswers, + veryNegativeAnswers, +]; + +let answer; // This should log "The ball has shaken!" // and return the answer. function shakeBall() { //Write your code in here - return ("The ball has shaken!"); + console.log("The ball has shaken!") + answer= randomAnswer(); + return answer; +} +function randomAnswer(){ + let list=listsOfAnswers[getRandom(4)]; + let answer=list[getRandom(5)]; + return answer; +} + +function getRandom(max){ + return Math.floor(Math.random()*max); } -console.log(shakeBall) /* This function should say whether the answer it is given is - very positive @@ -59,10 +110,28 @@ console.log(shakeBall) This function should expect to be called with any value which was returned by the shakeBall function. */ -function checkAnswer(answer) { +function checkAnswer(string) { //Write your code in here + for (let i=0; i<4;i++){ + let list=listsOfAnswers[i]; + for (let j = 0; j < 5; j++) { + let answerFromList = list[j]; + if (answerFromList === string) { + if (i === 0) { + return "very positive"; + } else if (i === 1) { + return "positive"; + } else if (i === 2) { + return "negative"; + } else { + return "very negative"; + } + } + } + } } + /* ================================== ======= TESTS - DO NOT MODIFY ===== From e03156b0ec4c6c6902ae17a7d019bae1f9425be6 Mon Sep 17 00:00:00 2001 From: Tony Arora <111275895+Tony-devops@users.noreply.github.com> Date: Wed, 30 Nov 2022 20:12:28 +0000 Subject: [PATCH 11/14] Update exercises/D-strings/exercise.js Co-authored-by: MitchLloyd --- exercises/D-strings/exercise.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/exercises/D-strings/exercise.js b/exercises/D-strings/exercise.js index 997a05816..ab897f523 100644 --- a/exercises/D-strings/exercise.js +++ b/exercises/D-strings/exercise.js @@ -1,5 +1,5 @@ // Start by creating a variable `message` -let message="Tony was here"; +let message = "Tony was here"; let type=typeof message; console.log(message); console.log(type); From 1a0fc7492b5198f93f029609c9e8255762a35507 Mon Sep 17 00:00:00 2001 From: Tony Arora <111275895+Tony-devops@users.noreply.github.com> Date: Wed, 30 Nov 2022 20:12:41 +0000 Subject: [PATCH 12/14] Update exercises/D-strings/exercise.js Co-authored-by: MitchLloyd --- exercises/D-strings/exercise.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/exercises/D-strings/exercise.js b/exercises/D-strings/exercise.js index ab897f523..b91b3a735 100644 --- a/exercises/D-strings/exercise.js +++ b/exercises/D-strings/exercise.js @@ -1,5 +1,5 @@ // Start by creating a variable `message` let message = "Tony was here"; -let type=typeof message; +let type= typeof message; console.log(message); console.log(type); From e42c3e6674325a0058e4fadf6ed3cfb704a630cc Mon Sep 17 00:00:00 2001 From: Tony Arora <111275895+Tony-devops@users.noreply.github.com> Date: Wed, 30 Nov 2022 20:14:30 +0000 Subject: [PATCH 13/14] Update exercise.js --- exercises/C-variables/exercise.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/exercises/C-variables/exercise.js b/exercises/C-variables/exercise.js index 1dd1a4fbe..a17507f15 100644 --- a/exercises/C-variables/exercise.js +++ b/exercises/C-variables/exercise.js @@ -1,5 +1,5 @@ // Start by creating a variable `greeting` -let greeting="Hello World" +let greeting = "Hello World"; console.log(greeting); console.log(greeting); console.log(greeting); From 7a462a46c2f5f0b7ff9f6010f7f7484f352c46a6 Mon Sep 17 00:00:00 2001 From: Tony Arora <111275895+Tony-devops@users.noreply.github.com> Date: Wed, 30 Nov 2022 20:15:23 +0000 Subject: [PATCH 14/14] Update exercise.js --- exercises/E-strings-concatenation/exercise.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/exercises/E-strings-concatenation/exercise.js b/exercises/E-strings-concatenation/exercise.js index a7a7b6fb5..8ffe13b36 100644 --- a/exercises/E-strings-concatenation/exercise.js +++ b/exercises/E-strings-concatenation/exercise.js @@ -1,5 +1,5 @@ // Start by creating a variable `message` -let first="My name is" -let second=" King Tony" -let message=first + second +let first = "My name is"; +let second = " King Tony"; +let message = first + second; console.log(message);