From ee2c7dc5da3fd2ae7c2a71831adc35f7150d7208 Mon Sep 17 00:00:00 2001 From: Bedi Omuri Date: Sat, 18 Feb 2023 21:10:36 +0000 Subject: [PATCH 1/7] mandatory coursework done --- README.md | 4 +--- mandatory/1-syntax-errors.js | 12 ++++++------ mandatory/2-logic-error.js | 7 +++---- mandatory/3-function-output.js | 4 ++++ 4 files changed, 14 insertions(+), 13 deletions(-) diff --git a/README.md b/README.md index 6611d00c3..7743addab 100644 --- a/README.md +++ b/README.md @@ -10,7 +10,6 @@ If you think you need to do more practice with the basics, then you can find som ## Setting up your code editor - There are some tools that will help you to write code. One of these, [Prettier](https://prettier.io/), formats your code, making it easier for you and others to read. ### 1. Install prettier @@ -25,10 +24,9 @@ There are some tools that will help you to write code. One of these, [Prettier]( - Search for `editor format` - Set `editor.formatOnSave` and `editor.formatOnPaste` to true - ## Running the code/tests -The files for the mandatory/extra exercises are intended to be run as jest tests. +The files for the mandatory/extra exercises are intended to be run as jest tests. - Once you have cloned the repository, run `npm install` once in the terminal to install jest (and any necessary dependencies). - To run the tests for all mandatory/extra exercises, run `npm test` diff --git a/mandatory/1-syntax-errors.js b/mandatory/1-syntax-errors.js index d9e004465..dda84c3e5 100644 --- a/mandatory/1-syntax-errors.js +++ b/mandatory/1-syntax-errors.js @@ -1,16 +1,16 @@ // 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 "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; - - return "The total is total"; + total = a + b; + return `The total is ${total}`; } /* diff --git a/mandatory/2-logic-error.js b/mandatory/2-logic-error.js index 9eb8c8cd7..ff5b064e1 100644 --- a/mandatory/2-logic-error.js +++ b/mandatory/2-logic-error.js @@ -1,16 +1,15 @@ // The syntax for these functions is valid but there are some errors, find them and fix them 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..fa13ed07d 100644 --- a/mandatory/3-function-output.js +++ b/mandatory/3-function-output.js @@ -1,9 +1,13 @@ // Add comments to explain what this function does. You're meant to use Google! +//this function generates a random value between 0(inclusive) and 10(exlusive) everytime is called +//Math.random generates a number between 0(inclusive ) and 1(exlusive) and then the function multiplies it with 10 function getRandomNumber() { return Math.random() * 10; } // Add comments to explain what this function does. You're meant to use Google! +//this function with combine/joins two strings together and will return a + function combine2Words(word1, word2) { return word1.concat(word2); } From 62233956905cf316b18ec5654cba8521f5459fbe Mon Sep 17 00:00:00 2001 From: Bedi Omuri Date: Sat, 18 Feb 2023 21:59:02 +0000 Subject: [PATCH 2/7] finished tax.js --- mandatory/3-function-output.js | 2 ++ mandatory/4-tax.js | 11 ++++++++--- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/mandatory/3-function-output.js b/mandatory/3-function-output.js index fa13ed07d..7c18fbd5f 100644 --- a/mandatory/3-function-output.js +++ b/mandatory/3-function-output.js @@ -13,6 +13,8 @@ function combine2Words(word1, word2) { } function concatenate(firstWord, secondWord, thirdWord) { + return `${firstWord.toString()} ${secondWord.toString()} ${thirdWord.toString()}`; + // 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. } diff --git a/mandatory/4-tax.js b/mandatory/4-tax.js index ba77c7ae2..afdd9e096 100644 --- a/mandatory/4-tax.js +++ b/mandatory/4-tax.js @@ -5,7 +5,9 @@ Sales tax is 20% of the price of the product. */ -function calculateSalesTax() {} +function calculateSalesTax(ProductPrice) { + return ProductPrice*0.2; +} /* CURRENCY FORMATTING @@ -17,8 +19,11 @@ function calculateSalesTax() {} Remember that the prices must include the sales tax (hint: you already wrote a function for this!) */ -function addTaxAndFormatCurrency() {} - +function addTaxAndFormatCurrency() { +let SalesTax=calculateSalesTax(ProductPrice) +let total=ProductPrice+SalesTax +return `£${total.toFixed(2)}`; +} /* =================================================== ======= TESTS - DO NOT MODIFY BELOW THIS LINE ===== From 4e976fafcb6c17fe2269e51713aff7e322a348a5 Mon Sep 17 00:00:00 2001 From: Bedi Omuri Date: Sun, 19 Feb 2023 20:50:34 +0000 Subject: [PATCH 3/7] trying to solve- extra --- extra/1-currency-conversion.js | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/extra/1-currency-conversion.js b/extra/1-currency-conversion.js index 75b3c6aab..1f60a05e0 100644 --- a/extra/1-currency-conversion.js +++ b/extra/1-currency-conversion.js @@ -5,7 +5,10 @@ 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 +18,13 @@ 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(PoundExchange) { + let exchangeRate = 5.7; + let fee=0.1; + PoundExchange = (PoundExchange * exchangeRate) *(1-fee); + return ` ${PoundExchange.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 04c6b589d1249bb6e649eb39ebf852df3640be72 Mon Sep 17 00:00:00 2001 From: Bedi Omuri Date: Mon, 20 Feb 2023 20:53:59 +0000 Subject: [PATCH 4/7] update-4-tax.js --- mandatory/4-tax.js | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/mandatory/4-tax.js b/mandatory/4-tax.js index afdd9e096..b6e07153f 100644 --- a/mandatory/4-tax.js +++ b/mandatory/4-tax.js @@ -6,7 +6,7 @@ */ function calculateSalesTax(ProductPrice) { - return ProductPrice*0.2; + return ProductPrice * 0.2; } /* @@ -19,10 +19,10 @@ function calculateSalesTax(ProductPrice) { Remember that the prices must include the sales tax (hint: you already wrote a function for this!) */ -function addTaxAndFormatCurrency() { -let SalesTax=calculateSalesTax(ProductPrice) -let total=ProductPrice+SalesTax -return `£${total.toFixed(2)}`; +function addTaxAndFormatCurrency(ProductPrice) { + let SalesTax = calculateSalesTax(ProductPrice); + let total = ProductPrice + SalesTax; + return `£${total.toFixed(2)}`; } /* =================================================== From 993cb4d9738ec59d4fc8baa50c489fd074c78972 Mon Sep 17 00:00:00 2001 From: Bedi Omuri Date: Mon, 20 Feb 2023 22:15:44 +0000 Subject: [PATCH 5/7] Update 4-tax.js --- mandatory/4-tax.js | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/mandatory/4-tax.js b/mandatory/4-tax.js index b6e07153f..bd01e6fd2 100644 --- a/mandatory/4-tax.js +++ b/mandatory/4-tax.js @@ -6,11 +6,14 @@ */ function calculateSalesTax(ProductPrice) { - return ProductPrice * 0.2; -} + let Tax = ProductPrice * 0.2; + let total = ProductPrice + Tax; + return total; +} /* CURRENCY FORMATTING + =================== The business has informed you that prices must have 2 decimal places They must also start with the currency symbol @@ -20,8 +23,9 @@ function calculateSalesTax(ProductPrice) { */ function addTaxAndFormatCurrency(ProductPrice) { - let SalesTax = calculateSalesTax(ProductPrice); - let total = ProductPrice + SalesTax; + let Tax = ProductPrice * 0.2; + let total = ProductPrice + Tax; + return `£${total.toFixed(2)}`; } /* From 6764a8c907172f4b8705fabf92977135f3063414 Mon Sep 17 00:00:00 2001 From: Bedi Omuri Date: Tue, 21 Feb 2023 23:08:11 +0000 Subject: [PATCH 6/7] currency-conversion.js update working with piping.js --- README.md | 2 +- extra/1-currency-conversion.js | 6 +++--- extra/2-piping.js | 11 ++++++----- 3 files changed, 10 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index 7743addab..5c862b7a6 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -# Coursework + # Coursework Like learning a musical instrument, programming requires daily practice. diff --git a/extra/1-currency-conversion.js b/extra/1-currency-conversion.js index 1f60a05e0..8d3f576f2 100644 --- a/extra/1-currency-conversion.js +++ b/extra/1-currency-conversion.js @@ -21,9 +21,9 @@ function convertToUSD(price) { function convertToBRL(PoundExchange) { let exchangeRate = 5.7; - let fee=0.1; - PoundExchange = (PoundExchange * exchangeRate) *(1-fee); - return ` ${PoundExchange.tofixed(2)}`; + let fee = 0.01; + PoundExchange = (PoundExchange * exchangeRate) * (1 - fee); + return parseFloat(PoundExchange.toFixed(2)); } /* ======= TESTS - DO NOT MODIFY ===== diff --git a/extra/2-piping.js b/extra/2-piping.js index b4f8c4c1b..79e31fdbf 100644 --- a/extra/2-piping.js +++ b/extra/2-piping.js @@ -16,15 +16,16 @@ 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(number) { + return '£'+ number; } From 4c2499111436202997a2112095da4e1371d385eb Mon Sep 17 00:00:00 2001 From: Bedi Omuri Date: Wed, 22 Feb 2023 22:28:04 +0000 Subject: [PATCH 7/7] update 2-piping.js --- extra/2-piping.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/extra/2-piping.js b/extra/2-piping.js index 79e31fdbf..19b2c5610 100644 --- a/extra/2-piping.js +++ b/extra/2-piping.js @@ -32,11 +32,13 @@ function format(number) { const startingValue = 2; // Why can this code be seen as bad practice? Comment your answer. -let badCode = +let badCode =format(multiply(add(startingValue, 10), 2)); /* BETTER PRACTICE */ -let goodCode = +let addedValue = add(startingValue, 10); +let multipliedValue = multiply(addedValue, 2); +let goodCode = format(multipliedValue); /* ======= TESTS - DO NOT MODIFY ===== There are some Tests in this file that will help you work out if your code is working.