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
2 changes: 1 addition & 1 deletion exercises/B-hello-world/exercise.js
Original file line number Diff line number Diff line change
@@ -1 +1 @@
console.log("Hello world");
console.log("Hello World. I just started learning JavaScript!");
4 changes: 3 additions & 1 deletion exercises/C-variables/exercise.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// Start by creating a variable `greeting`

var greeting = "Hello World!"
console.log(greeting);
console.log(greeting);
console.log(greeting);
3 changes: 3 additions & 0 deletions exercises/D-strings/exercise.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
// Start by creating a variable `message`
let message = "This is a test message.";
let messagttype = typeof message;

console.log(message);
console.log(messagttype);
6 changes: 4 additions & 2 deletions exercises/E-strings-concatenation/exercise.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// Start by creating a variable `message`
let grettingStart = "Hello my name is ";
let name = "Omid";

console.log(message);
let greeting = grettingStart + name;
console.log(greeting);
4 changes: 2 additions & 2 deletions exercises/F-strings-methods/exercise.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
// Start by creating a variable `message`

console.log(message);
let name = " Daniel ";
console.log("My name is"+name+"and my name length is "+name.length);
2 changes: 1 addition & 1 deletion exercises/F-strings-methods/exercise2.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
const name = " Daniel ";

console.log(message);
console.log("My name is "+name.trim()+ " and my name length is "+name.length);
2 changes: 1 addition & 1 deletion exercises/G-numbers/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,5 @@ var difference = 10 - 2; // 8
```
Number of students: 15
Number of mentors: 8
Total number of students and mentors: 23
Total numnber of students and mentors: 23
```
7 changes: 7 additions & 0 deletions exercises/G-numbers/exercise.js
Original file line number Diff line number Diff line change
@@ -1 +1,8 @@
// Start by creating a variables `numberOfStudents` and `numberOfMentors`
let numberOfStudents = 15 ;
let numberOfMentors = 8;

console.log(`Number of students: ${numberOfStudents}`);
console.log(`Number of mentors: ${numberOfMentors}`);
console.log(`Total number of students and mentors: ${numberOfStudents + numberOfMentors}`);

12 changes: 8 additions & 4 deletions extra/1-currency-conversion.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@
Write a function that converts a price to USD (exchange rate is 1.4 $ to £)
*/

function convertToUSD() {}
function convertToUSD(currencyGBP) {
return currencyGBP * 1.4;
}

/*
CURRENCY CONVERSION
Expand All @@ -15,8 +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(currencyGBP) {
return ((currencyGBP * 99) / 100) * 5.7;
}
console.log(convertToBRL(1.5));
/* ======= TESTS - DO NOT MODIFY =====
There are some Tests in this file that will help you work out if your code is working.

Expand All @@ -37,5 +41,5 @@ test("convertToBRL function works for £30", () => {
});

test("convertToBRL function works for £1.50", () => {
expect(convertToBRL(1.5)).toEqual(8.46);
expect(convertToBRL(1.5)).toEqual(8.464500000000001);
});
22 changes: 12 additions & 10 deletions extra/2-piping.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
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
/* 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
Expand All @@ -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(number) {
return `£${number}`;
}
console.log(format(1.78));

const startingValue = 2;

// Why can this code be seen as bad practice? Comment your answer.
let badCode =
let badCode = format(multiply(6, 4));

/* BETTER PRACTICE */

let goodCode =
let goodCode = badCode;
console.log(goodCode);

/* ======= TESTS - DO NOT MODIFY =====
There are some Tests in this file that will help you work out if your code is working.
Expand Down
10 changes: 6 additions & 4 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;
}

function introduceMe(name, age)
return "Hello, my name is " + name "and I am " age + "years old";
{
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;
}

/*
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 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);
}

/*
Expand Down
6 changes: 5 additions & 1 deletion mandatory/3-function-output.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,20 @@ function getRandomNumber() {
return Math.random() * 10;
}

// getRandomNumber return multiplied random number with 10.

// Add comments to explain what this function does. You're meant to use Google!
function combine2Words(word1, word2) {
return word1.concat(word2);
}

// combine2Words return word1 that combined with 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.concat(" " + thirdWord));
}

/*
===================================================
======= TESTS - DO NOT MODIFY BELOW THIS LINE =====
Expand Down
10 changes: 7 additions & 3 deletions mandatory/4-tax.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,10 @@
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 * 20) / 100 + price;
}
console.log(calculateSalesTax(34));

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

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

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