From 5c3aa8bb4a63e1374f60e9ae56a475967bbd78a1 Mon Sep 17 00:00:00 2001 From: howard-ss <102481688+howard-ss@users.noreply.github.com> Date: Tue, 22 Nov 2022 18:20:30 +0000 Subject: [PATCH 1/4] done 'exercise' & 'mandatory' tasks done 'exercise' and 'mandatory' tasks --- exercises/B-hello-world/exercise.js | 7 ++++- exercises/C-variables/exercise.js | 4 +++ exercises/D-strings/exercise.js | 4 +++ exercises/E-strings-concatenation/exercise.js | 3 +++ exercises/F-strings-methods/exercise.js | 5 ++++ exercises/F-strings-methods/exercise2.js | 8 +++++- exercises/G-numbers/README.md | 2 +- exercises/G-numbers/exercise.js | 9 +++++++ exercises/I-floats/exercise.js | 8 ++++++ exercises/J-functions/exercise.js | 8 ++++++ exercises/J-functions/exercise2.js | 3 +++ exercises/K-functions-parameters/exercise.js | 6 +++-- exercises/K-functions-parameters/exercise2.js | 5 ++++ exercises/K-functions-parameters/exercise3.js | 5 ++++ exercises/K-functions-parameters/exercise4.js | 6 ++++- exercises/K-functions-parameters/exercise5.js | 6 +++++ exercises/L-functions-nested/exercise.js | 15 +++++++++++ extra/1-currency-conversion.js | 11 +++++--- extra/2-piping.js | 27 ++++++++++--------- mandatory/1-syntax-errors.js | 11 ++++---- mandatory/2-logic-error.js | 8 +++--- mandatory/3-function-output.js | 4 +++ mandatory/4-tax.js | 19 ++++++++----- 23 files changed, 147 insertions(+), 37 deletions(-) diff --git a/exercises/B-hello-world/exercise.js b/exercises/B-hello-world/exercise.js index b179ee953..b9e17e0d9 100644 --- a/exercises/B-hello-world/exercise.js +++ b/exercises/B-hello-world/exercise.js @@ -1 +1,6 @@ -console.log("Hello world"); +console.log(22); +console.log("Hello World!"); +console.log("Hi World!"); +console.log("Hi World!"); +console.log("Hi World!"); + diff --git a/exercises/C-variables/exercise.js b/exercises/C-variables/exercise.js index a6bbb9786..f3b299554 100644 --- a/exercises/C-variables/exercise.js +++ b/exercises/C-variables/exercise.js @@ -1,3 +1,7 @@ // 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..a73c3ce4e 100644 --- a/exercises/D-strings/exercise.js +++ b/exercises/D-strings/exercise.js @@ -1,3 +1,7 @@ // 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..5ae195576 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` +let messageStart = "Hello, my name is "; +let messageName = "Daniel"; +let message = messageStart + messageName console.log(message); diff --git a/exercises/F-strings-methods/exercise.js b/exercises/F-strings-methods/exercise.js index 2cffa6a81..5f317c30c 100644 --- a/exercises/F-strings-methods/exercise.js +++ b/exercises/F-strings-methods/exercise.js @@ -1,3 +1,8 @@ // Start by creating a variable `message` +const messageName = "Daniel"; +let messageLength = messageName.length + +let message = "My name is Daniel and my name is " + messageLength + " characters long"; + console.log(message); diff --git a/exercises/F-strings-methods/exercise2.js b/exercises/F-strings-methods/exercise2.js index b4b46943d..994213c54 100644 --- a/exercises/F-strings-methods/exercise2.js +++ b/exercises/F-strings-methods/exercise2.js @@ -1,3 +1,9 @@ -const name = " Daniel "; + +const Name = " Daniel "; +const trimName = Name.trim(); +let nameLength = trimName.length; + +let message = "My name is " + trimName + " and my name is "+ nameLength + " characters long" + console.log(message); diff --git a/exercises/G-numbers/README.md b/exercises/G-numbers/README.md index 6775ad18f..75136adf1 100644 --- a/exercises/G-numbers/README.md +++ b/exercises/G-numbers/README.md @@ -6,7 +6,7 @@ Unlike strings, numbers do not need to be wrapped in quotes. var age = 30; ``` -You can use mathematical operators to caclulate numbers: +You can use mathematical operators to calculate numbers: ```js var sum = 10 + 2; // 12 diff --git a/exercises/G-numbers/exercise.js b/exercises/G-numbers/exercise.js index 49e7bc00b..9ce7aca5a 100644 --- a/exercises/G-numbers/exercise.js +++ b/exercises/G-numbers/exercise.js @@ -1 +1,10 @@ // Start by creating a variables `numberOfStudents` and `numberOfMentors` + + let numberOfStudents = 15; + let numberOfMentors = 8; + + let totalNum = numberOfStudents + numberOfMentors; + + console.log("Number of students: "+ numberOfStudents); + console.log("Number of mentors: " + numberOfMentors); + console.log("Total number of students and mentors: "+ totalNum); \ No newline at end of file diff --git a/exercises/I-floats/exercise.js b/exercises/I-floats/exercise.js index a5bbcd852..11f569788 100644 --- a/exercises/I-floats/exercise.js +++ b/exercises/I-floats/exercise.js @@ -1,2 +1,10 @@ var numberOfStudents = 15; var numberOfMentors = 8; + +let totalNum = numberOfStudents + numberOfMentors; + +let studentPercentage = (numberOfStudents / totalNum) * 100; +let mentorPercentage = (numberOfMentors / totalNum) * 100; + +console.log("Percentage students: "+Math.round(studentPercentage)+"%"); +console.log("Percentage mentors: " +Math.round(mentorPercentage)+"%"); \ No newline at end of file diff --git a/exercises/J-functions/exercise.js b/exercises/J-functions/exercise.js index 0ae5850e5..0231de637 100644 --- a/exercises/J-functions/exercise.js +++ b/exercises/J-functions/exercise.js @@ -1,7 +1,15 @@ function halve(number) { // complete the function here + return number / 2; } var result = halve(12); +// let res2 = halve (88); +// let res3 = halve (100); console.log(result); + +// console.log(res2); +// console.log(res3); + + diff --git a/exercises/J-functions/exercise2.js b/exercises/J-functions/exercise2.js index 82ef5e780..f36e071c1 100644 --- a/exercises/J-functions/exercise2.js +++ b/exercises/J-functions/exercise2.js @@ -1,7 +1,10 @@ function triple(number) { // complete function here + return number * 3 } var result = triple(12); console.log(result); + + diff --git a/exercises/K-functions-parameters/exercise.js b/exercises/K-functions-parameters/exercise.js index 8d5db5e69..ce474c66b 100644 --- a/exercises/K-functions-parameters/exercise.js +++ b/exercises/K-functions-parameters/exercise.js @@ -1,9 +1,11 @@ // 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); + diff --git a/exercises/K-functions-parameters/exercise2.js b/exercises/K-functions-parameters/exercise2.js index db7a8904b..933a99dc9 100644 --- a/exercises/K-functions-parameters/exercise2.js +++ b/exercises/K-functions-parameters/exercise2.js @@ -1,5 +1,10 @@ // 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..ff9160971 100644 --- a/exercises/K-functions-parameters/exercise3.js +++ b/exercises/K-functions-parameters/exercise3.js @@ -1,5 +1,10 @@ // Write your function here +function createGreeting(name){ + return "Hello, my name is " + 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..4e80988ea 100644 --- a/exercises/K-functions-parameters/exercise4.js +++ b/exercises/K-functions-parameters/exercise4.js @@ -1,5 +1,9 @@ // Declare your function first - + function add(a,b) { + return a + b; + } // Call the function and assign to a variable `sum` + let sum = add(13,124); console.log(sum); + diff --git a/exercises/K-functions-parameters/exercise5.js b/exercises/K-functions-parameters/exercise5.js index 7c5bcd605..bdcd084b4 100644 --- a/exercises/K-functions-parameters/exercise5.js +++ b/exercises/K-functions-parameters/exercise5.js @@ -1,5 +1,11 @@ // Declare your function here + function createLongGreeting(str,num) { + return "Hello, my name is " + str + " and I'm " + num + " years old"; + } + + 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..1f17304e2 100644 --- a/exercises/L-functions-nested/exercise.js +++ b/exercises/L-functions-nested/exercise.js @@ -3,3 +3,18 @@ var mentor2 = "Irina"; var mentor3 = "Mimi"; var mentor4 = "Rob"; var mentor5 = "Yohannes"; + +function shoutyGreeting(){ + console.log("HELLO " + mentor1.toUpperCase()); + console.log("HELLO " + mentor2.toUpperCase()); + console.log("HELLO " + mentor3.toUpperCase()); + console.log("HELLO " + mentor4.toUpperCase()); + console.log("HELLO " + mentor5.toUpperCase()); + +} + +shoutyGreeting() + + + + diff --git a/extra/1-currency-conversion.js b/extra/1-currency-conversion.js index 75b3c6aab..4652d196e 100644 --- a/extra/1-currency-conversion.js +++ b/extra/1-currency-conversion.js @@ -5,17 +5,22 @@ Write a function that converts a price to USD (exchange rate is 1.4 $ to £) */ -function convertToUSD() {} +function convertToUSD(pound) { + return pound * 1.4; +} /* CURRENCY CONVERSION =================== The business is now breaking into the Brazilian market Write a new function for converting to the Brazilian real (exchange rate is 5.7 BRL to £) - 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. + 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(pound) { + return ((pound * 0.99)* 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. diff --git a/extra/2-piping.js b/extra/2-piping.js index b4f8c4c1b..34f7872f9 100644 --- a/extra/2-piping.js +++ b/extra/2-piping.js @@ -4,38 +4,39 @@ 1. Write 3 functions: - one that adds 2 numbers together - one that multiplies 2 numbers together - - one that formats a number so it's returned as a string with a £ sign before it (e.g. 20 -> £20) + - one that formats a number so it's returned as a string with a £ sign before it + (e.g. 20 -> £20) - 2. Using the variable startingValue as input, perform the following operations using your functions all - on one line (assign the result to the variable badCode): + 2. Using the variable startingValue as input, perform the following operations + using your functions all on one line (assign the result to the variable badCode): - add 10 to startingValue - multiply the result by 2 - format it - 3. Write a more readable version of what you wrote in step 2 under the BETTER PRACTICE comment. Assign - the final result to the variable goodCode + 3. Write a more readable version of what you wrote in step 2 under the BETTER + PRACTICE comment. Assign 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(a) { + return "£"+a; } const startingValue = 2; // Why can this code be seen as bad practice? Comment your answer. -let badCode = +let badCode =format(multiply(add(startingValue(2)))); /* BETTER PRACTICE */ -let goodCode = +let goodCode = /* ======= 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/mandatory/1-syntax-errors.js b/mandatory/1-syntax-errors.js index a10cc9ac2..fc047f727 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; } /* diff --git a/mandatory/2-logic-error.js b/mandatory/2-logic-error.js index 9cca7603b..4902e77f2 100644 --- a/mandatory/2-logic-error.js +++ b/mandatory/2-logic-error.js @@ -1,16 +1,16 @@ // 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..1cd367193 100644 --- a/mandatory/3-function-output.js +++ b/mandatory/3-function-output.js @@ -1,16 +1,20 @@ // Add comments to explain what this function does. You're meant to use Google! function getRandomNumber() { return Math.random() * 10; + // Math.random() method returns a random floating-point number between 0.0 and 1.0. + // This can be used to generate random number. } // Add comments to explain what this function does. You're meant to use Google! function combine2Words(word1, word2) { return word1.concat(word2); + // .concat() method returns a string containing all the string values in a node-set concatenated together. } 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 } /* diff --git a/mandatory/4-tax.js b/mandatory/4-tax.js index ba77c7ae2..c88599723 100644 --- a/mandatory/4-tax.js +++ b/mandatory/4-tax.js @@ -1,23 +1,30 @@ /* 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. + 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() {} +function calculateSalesTax(price) { + return (price * 1.2 ); +} /* 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 + 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!) + Remember that the prices must include the sales tax (hint: you already + wrote a function for this!) */ -function addTaxAndFormatCurrency() {} +function addTaxAndFormatCurrency(price) { + return "£"+calculateSalesTax(price).toFixed(2); + +} /* =================================================== From 5e2641378f42f21246b40bff48f58805ce448ab8 Mon Sep 17 00:00:00 2001 From: howard-ss <102481688+howard-ss@users.noreply.github.com> Date: Thu, 24 Nov 2022 11:41:18 +0000 Subject: [PATCH 2/4] updated 2 tasks in extra updated 2 tasks in extra: 1- currency-conversion.js; 2-piping.js --- extra/1-currency-conversion.js | 9 +++++---- extra/2-piping.js | 10 ++++++---- extra/3-magic-8-ball.js | 9 +++++++-- 3 files changed, 18 insertions(+), 10 deletions(-) diff --git a/extra/1-currency-conversion.js b/extra/1-currency-conversion.js index 4652d196e..22e28aa9a 100644 --- a/extra/1-currency-conversion.js +++ b/extra/1-currency-conversion.js @@ -13,13 +13,14 @@ function convertToUSD(pound) { CURRENCY CONVERSION =================== The business is now breaking into the Brazilian market - Write a new function for converting to the Brazilian real (exchange rate is 5.7 BRL to £) - They have also decided that they should add a 1% fee to all foreign transactions, + Write a new function for converting to the Brazilian real (exchange rate is + 5.7 BRL to £) + 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(pound) { - return ((pound * 0.99)* 5.7).toFixed(2) +function convertToBRL(poundmoney) { + return Number(((poundmoney * 0.99)* 5.7).toFixed(2)) } /* ======= TESTS - DO NOT MODIFY ===== diff --git a/extra/2-piping.js b/extra/2-piping.js index 34f7872f9..ef2b010e0 100644 --- a/extra/2-piping.js +++ b/extra/2-piping.js @@ -4,8 +4,8 @@ 1. Write 3 functions: - one that adds 2 numbers together - one that multiplies 2 numbers together - - one that formats a number so it's returned as a string with a £ sign before it - (e.g. 20 -> £20) + - one that formats a number so it's returned as a string with a £ sign before + it (e.g. 20 -> £20) 2. Using the variable startingValue as input, perform the following operations using your functions all on one line (assign the result to the variable badCode): @@ -32,11 +32,13 @@ function format(a) { const startingValue = 2; // Why can this code be seen as bad practice? Comment your answer. -let badCode =format(multiply(add(startingValue(2)))); +let badCode = format( multiply(2, add(startingValue,10))); /* BETTER PRACTICE */ +let goodadd = add(startingValue,10); +let goodmultiply = multiply(2,goodadd); -let goodCode = +let goodCode = format(goodmultiply); /* ======= 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..70fe4bcf0 100644 --- a/extra/3-magic-8-ball.js +++ b/extra/3-magic-8-ball.js @@ -45,8 +45,12 @@ // This should log "The ball has shaken!" // and return the answer. -function shakeBall() { +function shakeBall(answer) { //Write your code in here + if ( answer === positive ) { + + console.log("The ball has shaken " + answer ); + } } /* @@ -56,7 +60,8 @@ function shakeBall() { - negative - very negative - This function should expect to be called with any value which was returned by the shakeBall function. + This function should expect to be called with any value which was returned + by the shakeBall function. */ function checkAnswer(answer) { //Write your code in here From a92ba75c9bd14a64af8db942c991116589e91c68 Mon Sep 17 00:00:00 2001 From: howard-ss <102481688+howard-ss@users.noreply.github.com> Date: Thu, 24 Nov 2022 17:57:03 +0000 Subject: [PATCH 3/4] update exercise update exercise --- exercises/G-numbers/exercise.js | 1 + 1 file changed, 1 insertion(+) diff --git a/exercises/G-numbers/exercise.js b/exercises/G-numbers/exercise.js index 9ce7aca5a..514d3347b 100644 --- a/exercises/G-numbers/exercise.js +++ b/exercises/G-numbers/exercise.js @@ -1,5 +1,6 @@ // Start by creating a variables `numberOfStudents` and `numberOfMentors` + let numberOfStudents = 15; let numberOfMentors = 8; From 73e8ba0a8237ad8d0684757c89d86f191b4de762 Mon Sep 17 00:00:00 2001 From: howard-ss <102481688+howard-ss@users.noreply.github.com> Date: Tue, 29 Nov 2022 18:03:48 +0000 Subject: [PATCH 4/4] update after double checked repo updated all --- exercises/B-hello-world/exercise.js | 13 ++++++++----- exercises/D-strings/exercise.js | 6 +++--- exercises/E-strings-concatenation/exercise.js | 4 ++-- exercises/F-strings-methods/exercise.js | 7 ++++--- exercises/F-strings-methods/exercise2.js | 9 +++++---- exercises/G-numbers/exercise.js | 16 +++++++++------- exercises/I-floats/exercise.js | 7 +++++-- exercises/J-functions/exercise.js | 6 +++--- exercises/J-functions/exercise2.js | 2 +- exercises/K-functions-parameters/exercise.js | 3 +-- exercises/K-functions-parameters/exercise2.js | 3 +-- exercises/K-functions-parameters/exercise3.js | 6 +++--- exercises/K-functions-parameters/exercise5.js | 8 +++----- extra/1-currency-conversion.js | 13 ++++++++----- mandatory/1-syntax-errors.js | 6 +++--- mandatory/4-tax.js | 6 +++--- 16 files changed, 62 insertions(+), 53 deletions(-) diff --git a/exercises/B-hello-world/exercise.js b/exercises/B-hello-world/exercise.js index b9e17e0d9..1c8223555 100644 --- a/exercises/B-hello-world/exercise.js +++ b/exercises/B-hello-world/exercise.js @@ -1,6 +1,9 @@ -console.log(22); -console.log("Hello World!"); -console.log("Hi World!"); -console.log("Hi World!"); -console.log("Hi World!"); + +let greeting = '1'; + +//console.log(22); +console.log(greeting); +console.log(greeting); +console.log(greeting); +//console.log("Hi World!"); diff --git a/exercises/D-strings/exercise.js b/exercises/D-strings/exercise.js index a73c3ce4e..0e0b6329a 100644 --- a/exercises/D-strings/exercise.js +++ b/exercises/D-strings/exercise.js @@ -1,7 +1,7 @@ // Start by creating a variable `message` -let message = "This is a string"; -let messageType = typeof message; +let message = [] ; +//let messageType = typeof message; console.log(message); -console.log(messageType); +console.log(typeof message); diff --git a/exercises/E-strings-concatenation/exercise.js b/exercises/E-strings-concatenation/exercise.js index 5ae195576..8a12a8d8a 100644 --- a/exercises/E-strings-concatenation/exercise.js +++ b/exercises/E-strings-concatenation/exercise.js @@ -1,6 +1,6 @@ // Start by creating a variable `message` -let messageStart = "Hello, my name is "; +//let messageStart = "Hello, my name is "; let messageName = "Daniel"; -let message = messageStart + messageName +let message = "Hello, my name is " + messageName console.log(message); diff --git a/exercises/F-strings-methods/exercise.js b/exercises/F-strings-methods/exercise.js index 5f317c30c..c53bec4e7 100644 --- a/exercises/F-strings-methods/exercise.js +++ b/exercises/F-strings-methods/exercise.js @@ -1,8 +1,9 @@ // Start by creating a variable `message` -const messageName = "Daniel"; -let messageLength = messageName.length +const name = "Daniel"; +//let messageLength = messageName.length -let message = "My name is Daniel and my name is " + messageLength + " characters long"; +//let message = "My name is Daniel and my name is " + messageLength + " characters long"; +let message = `My name is ${name} and my name is ${name.length} characters long`; console.log(message); diff --git a/exercises/F-strings-methods/exercise2.js b/exercises/F-strings-methods/exercise2.js index 994213c54..4a20a7735 100644 --- a/exercises/F-strings-methods/exercise2.js +++ b/exercises/F-strings-methods/exercise2.js @@ -1,9 +1,10 @@ -const Name = " Daniel "; -const trimName = Name.trim(); -let nameLength = trimName.length; +const name = " Johnson "; +//const trimName = Name.trim(); +//let nameLength = trimName.length; -let message = "My name is " + trimName + " and my name is "+ nameLength + " characters long" +//let message = "My name is " + trimName + " and my name is "+ nameLength + " characters long" +let message = `My name is ${name.trim()} and my name is ${(name.trim().length)} characters long`; console.log(message); diff --git a/exercises/G-numbers/exercise.js b/exercises/G-numbers/exercise.js index 514d3347b..a6a0ec02e 100644 --- a/exercises/G-numbers/exercise.js +++ b/exercises/G-numbers/exercise.js @@ -1,11 +1,13 @@ // Start by creating a variables `numberOfStudents` and `numberOfMentors` - - let numberOfStudents = 15; - let numberOfMentors = 8; + let numberOfMentors = 10; let totalNum = numberOfStudents + numberOfMentors; - - console.log("Number of students: "+ numberOfStudents); - console.log("Number of mentors: " + numberOfMentors); - console.log("Total number of students and mentors: "+ totalNum); \ No newline at end of file + + //console.log("Number of students: "+ numberOfStudents); + //console.log("Number of mentors: " + numberOfMentors); + //console.log("Total number of students and mentors: "+ totalNum); + + console.log(`Number of students: ${numberOfStudents}`); + console.log(`Number of mentors: ${numberOfMentors}`); + console.log(`Total number of students and mentors: ${totalNum}`); \ No newline at end of file diff --git a/exercises/I-floats/exercise.js b/exercises/I-floats/exercise.js index 11f569788..1b8b8d6d1 100644 --- a/exercises/I-floats/exercise.js +++ b/exercises/I-floats/exercise.js @@ -6,5 +6,8 @@ let totalNum = numberOfStudents + numberOfMentors; let studentPercentage = (numberOfStudents / totalNum) * 100; let mentorPercentage = (numberOfMentors / totalNum) * 100; -console.log("Percentage students: "+Math.round(studentPercentage)+"%"); -console.log("Percentage mentors: " +Math.round(mentorPercentage)+"%"); \ No newline at end of file +console.log(`Percentage students: ${Math.round(studentPercentage)}%`); +console.log(`Percentage mentors: ${Math.round(mentorPercentage)}%`); + +//console.log("Percentage students: "+Math.round(studentPercentage)+"%"); +//console.log("Percentage mentors: " +Math.round(mentorPercentage)+"%"); \ No newline at end of file diff --git a/exercises/J-functions/exercise.js b/exercises/J-functions/exercise.js index 0231de637..816398af5 100644 --- a/exercises/J-functions/exercise.js +++ b/exercises/J-functions/exercise.js @@ -3,13 +3,13 @@ function halve(number) { return number / 2; } -var result = halve(12); +let result = halve(12); // let res2 = halve (88); // let res3 = halve (100); console.log(result); -// console.log(res2); -// console.log(res3); +console.log(halve(88)); +console.log(halve(122)); diff --git a/exercises/J-functions/exercise2.js b/exercises/J-functions/exercise2.js index f36e071c1..bbc16962a 100644 --- a/exercises/J-functions/exercise2.js +++ b/exercises/J-functions/exercise2.js @@ -3,7 +3,7 @@ function triple(number) { return number * 3 } -var result = triple(12); +let result = triple(12); console.log(result); diff --git a/exercises/K-functions-parameters/exercise.js b/exercises/K-functions-parameters/exercise.js index ce474c66b..2f73b955a 100644 --- a/exercises/K-functions-parameters/exercise.js +++ b/exercises/K-functions-parameters/exercise.js @@ -3,9 +3,8 @@ 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); +let result = multiply(3, 4); console.log(result); diff --git a/exercises/K-functions-parameters/exercise2.js b/exercises/K-functions-parameters/exercise2.js index 933a99dc9..6b54922af 100644 --- a/exercises/K-functions-parameters/exercise2.js +++ b/exercises/K-functions-parameters/exercise2.js @@ -3,8 +3,7 @@ function divide(a,b) { return a / b; } - -var result = divide(3, 4); +let result = divide(3, 4); console.log(result); diff --git a/exercises/K-functions-parameters/exercise3.js b/exercises/K-functions-parameters/exercise3.js index ff9160971..874942398 100644 --- a/exercises/K-functions-parameters/exercise3.js +++ b/exercises/K-functions-parameters/exercise3.js @@ -1,10 +1,10 @@ // Write your function here function createGreeting(name){ - return "Hello, my name is " + name; + // return "Hello, my name is " + name; + return `Hello, my name is ${name}`; } - -var greeting = createGreeting("Daniel"); +let greeting = createGreeting("Daniel"); console.log(greeting); diff --git a/exercises/K-functions-parameters/exercise5.js b/exercises/K-functions-parameters/exercise5.js index bdcd084b4..0f32468d8 100644 --- a/exercises/K-functions-parameters/exercise5.js +++ b/exercises/K-functions-parameters/exercise5.js @@ -1,10 +1,8 @@ // Declare your function here - function createLongGreeting(str,num) { - return "Hello, my name is " + str + " and I'm " + num + " years old"; + function createLongGreeting(str,age) { + //return "Hello, my name is " + str + " and I'm " + age + " years old"; + return `Hello, my name is ${str} and I'm ${age} years old`; } - - - const greeting = createLongGreeting("Daniel", 30); console.log(greeting); diff --git a/extra/1-currency-conversion.js b/extra/1-currency-conversion.js index 22e28aa9a..c00671bc7 100644 --- a/extra/1-currency-conversion.js +++ b/extra/1-currency-conversion.js @@ -5,10 +5,9 @@ Write a function that converts a price to USD (exchange rate is 1.4 $ to £) */ -function convertToUSD(pound) { - return pound * 1.4; +function convertToUSD(price) { + return price * 1.4; } - /* CURRENCY CONVERSION =================== @@ -19,8 +18,12 @@ function convertToUSD(pound) { which means you only convert 99% of the £ to BRL. */ -function convertToBRL(poundmoney) { - return Number(((poundmoney * 0.99)* 5.7).toFixed(2)) +function convertToBRL(price) { + let priceAfterFee = price * 0.99; + let priceInBRL = priceAfterFee * 5.7; + return Math.round(priceInBRL*100)/100; + + //return Number(((poundmoney * 0.99)* 5.7).toFixed(2)) } /* ======= TESTS - DO NOT MODIFY ===== diff --git a/mandatory/1-syntax-errors.js b/mandatory/1-syntax-errors.js index fc047f727..c105ea51f 100644 --- a/mandatory/1-syntax-errors.js +++ b/mandatory/1-syntax-errors.js @@ -9,9 +9,9 @@ function introduceMe(name, age) { } function getTotal(a, b) { - total = a + b; - - return "The total is " + total; + let total = a + b; + return `The total is ${total}`; + //return "The total is " + total; } /* diff --git a/mandatory/4-tax.js b/mandatory/4-tax.js index c88599723..fd41a0c3c 100644 --- a/mandatory/4-tax.js +++ b/mandatory/4-tax.js @@ -4,11 +4,9 @@ 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(price) { return (price * 1.2 ); } - /* CURRENCY FORMATTING =================== @@ -22,7 +20,9 @@ function calculateSalesTax(price) { */ function addTaxAndFormatCurrency(price) { - return "£"+calculateSalesTax(price).toFixed(2); + let priceWithTax = calculateSalesTax(price); + return "£"+priceWithTax.toFixed(2); + // return "£"+calculateSalesTax(price).toFixed(2); }