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
4 changes: 1 addition & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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: 7 additions & 6 deletions mandatory/1-syntax-errors.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
// 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;

Choose a reason for hiding this comment

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

Nice!

}

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`;

Choose a reason for hiding this comment

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

Nice!


}

function getTotal(a, b) {
total = a ++ b;
total = a + b;

return "The total is total";
return `The total is ${total}`;

Choose a reason for hiding this comment

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

Good

}

/*
Expand All @@ -24,7 +26,6 @@ To run the tests for just this one file, type `npm test -- --testPathPattern 1-s

===================================================
*/

test("addNumbers adds numbers correctly", () => {
expect(addNumbers(3, 4, 6)).toEqual(13);
});
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;

Choose a reason for hiding this comment

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

Nice and tidy, like it

}

/*
Expand Down
7 changes: 4 additions & 3 deletions mandatory/3-function-output.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,17 @@
function getRandomNumber() {

Choose a reason for hiding this comment

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

Can you add the comment here to explain what this does?

return Math.random() * 10;
}
//It gives random number between 0 to 10.

// Add comments to explain what this function does. You're meant to use Google!

Choose a reason for hiding this comment

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

and here too...

function combine2Words(word1, word2) {
return word1.concat(word2);
}

function concatenate(firstWord, secondWord, thirdWord) {
// It combines 2 words.
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}`;

Choose a reason for hiding this comment

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

Nice use of string interpolation

}

/*
Expand All @@ -23,7 +25,6 @@ To run the tests for just this one file, type `npm test -- --testPathPattern 3-f
(Reminder: You must have run `npm install` one time before this will work!)
==================================
*/

test("concatenate example #1", () => {
expect(concatenate("code", "your", "future")).toEqual("code your future");
});
Expand Down
9 changes: 7 additions & 2 deletions mandatory/4-tax.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,10 @@
Sales tax is 20% of the price of the product.
*/

function calculateSalesTax() {}
function calculateSalesTax(sales) {
const tax = 0.2 * sales;

Choose a reason for hiding this comment

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

Good, clear labelling

return tax + sales;
}

/*
CURRENCY FORMATTING
Expand All @@ -17,7 +20,9 @@ function calculateSalesTax() {}
Remember that the prices must include the sales tax (hint: you already wrote a function for this!)
*/

function addTaxAndFormatCurrency() {}
function addTaxAndFormatCurrency(sales) {
return "£" + calculateSalesTax(sales).toFixed(2);
}

/*
===================================================
Expand Down