Skip to content
This repository was archived by the owner on Jan 14, 2024. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 2 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Coursework
# Coursework

Like learning a musical instrument, programming requires daily practice.

Expand All @@ -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
Expand All @@ -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`
Expand Down
13 changes: 11 additions & 2 deletions extra/1-currency-conversion.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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) {

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi Bedrije

what you did here is was wonderful and also you can make it short like

function convertToBRL(price) {
let priceConverted = price * 0.99 * 5.7
return parseFloat(priceConverted .toFixed(2))
}

Thanks

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for your feedback Abubakar

let exchangeRate = 5.7;
let fee = 0.01;
PoundExchange = (PoundExchange * exchangeRate) * (1 - fee);
return parseFloat(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.
Expand Down
17 changes: 10 additions & 7 deletions extra/2-piping.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,26 +16,29 @@
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;

}

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.
Expand Down
12 changes: 6 additions & 6 deletions mandatory/1-syntax-errors.js
Original file line number Diff line number Diff line change
@@ -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}`;
}

/*
Expand Down
7 changes: 3 additions & 4 deletions mandatory/2-logic-error.js
Original file line number Diff line number Diff line change
@@ -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;
}

/*
Expand Down
6 changes: 6 additions & 0 deletions mandatory/3-function-output.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,20 @@
// 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);
}

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.
}
Expand Down
13 changes: 11 additions & 2 deletions mandatory/4-tax.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,15 @@
Sales tax is 20% of the price of the product.
*/

function calculateSalesTax() {}
function calculateSalesTax(ProductPrice) {
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
Expand All @@ -17,8 +22,12 @@ function calculateSalesTax() {}
Remember that the prices must include the sales tax (hint: you already wrote a function for this!)
*/

function addTaxAndFormatCurrency() {}
function addTaxAndFormatCurrency(ProductPrice) {
let Tax = ProductPrice * 0.2;
let total = ProductPrice + Tax;

return `£${total.toFixed(2)}`;
}
/*
===================================================
======= TESTS - DO NOT MODIFY BELOW THIS LINE =====
Expand Down