Skip to content
This repository was archived by the owner on Jan 14, 2024. It is now read-only.
Closed
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");
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);
4 changes: 3 additions & 1 deletion exercises/D-strings/exercise.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// Start by creating a variable `message`

let message = "This is a string";
console.log(message);
let messgeType = typeof message;
console.log(messgeType);
6 changes: 5 additions & 1 deletion exercises/E-strings-concatenation/exercise.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
// Start by creating a variable `message`
let greeting = "Hello, my name is ";
let name = "Ibrahim Isleem";

console.log(message);
let message = greeting + name;

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

console.log(message);
let name = "Ibrahim";
let namelenght = name.length;
let message = `My ${name} is Daniel and my name is ${namelenght} characters long`;
console.log(message);
4 changes: 2 additions & 2 deletions 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);
let message = name.trim();
console.log(message);
6 changes: 6 additions & 0 deletions exercises/G-numbers/exercise.js
Original file line number Diff line number Diff line change
@@ -1 +1,7 @@
// Start by creating a variables `numberOfStudents` and `numberOfMentors`
let numberOfStudents = 15;
let numberOfMentors = 8;
let sum = numberOfStudents + numberOfMentors;
console.log(`Number of students: ${numberOfStudents}`);
console.log(`Number of Mentors: ${numberOfMentors}`);
console.log(`Total numnber of students and mentors: ${sum}`);
8 changes: 8 additions & 0 deletions exercises/I-floats/exercise.js
Original file line number Diff line number Diff line change
@@ -1,2 +1,10 @@
var numberOfStudents = 15;
var numberOfMentors = 8;
var percentageOfStudents = Math.round(
(numberOfStudents / (numberOfStudents + numberOfMentors)) * 100
);
var percentageOfMentors = Math.round(
(numberOfMentors / (numberOfStudents + numberOfMentors)) * 100
);
console.log(`Percentage students: ${percentageOfStudents}%`);
console.log(`Percentage Mentors: ${percentageOfMentors}%`);
5 changes: 3 additions & 2 deletions exercises/J-functions/exercise.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
function halve(number) {
// complete the function here
// complete the function here
return number / 2;
}

var result = halve(12);

console.log(result);
console.log(result);
5 changes: 3 additions & 2 deletions exercises/J-functions/exercise2.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
function triple(number) {
// complete function here
// complete function here
return number * 3;
}

var result = triple(12);

console.log(result);
console.log(result);
7 changes: 4 additions & 3 deletions exercises/K-functions-parameters/exercise.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
// Complete the function so that it takes input parameters
function multiply() {
// Calculate the result of the function and return it
function multiply(num1, num2) {
// Calculate the result of the function and return it
return num1 * num2;
}

// Assign the result of calling the function the variable `result`
var result = multiply(3, 4);

console.log(result);
console.log(result);
6 changes: 4 additions & 2 deletions exercises/K-functions-parameters/exercise2.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
// Declare your function first

function divide(num1, num2) {
return num1 / num2;
}
var result = divide(3, 4);

console.log(result);
console.log(result);
8 changes: 5 additions & 3 deletions exercises/K-functions-parameters/exercise3.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
// Write your function here
function createGreeting(name) {
return `Hello, my name is ${name}`;
}
var greeting = createGreeting("Ibrahim");

var greeting = createGreeting("Daniel");

console.log(greeting);
console.log(greeting);
8 changes: 5 additions & 3 deletions exercises/K-functions-parameters/exercise4.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
// Declare your function first

function add(a, b) {
return a + b;
}
// Call the function and assign to a variable `sum`

console.log(sum);
var sum = add(13, 124);
console.log(sum);
7 changes: 5 additions & 2 deletions exercises/K-functions-parameters/exercise5.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
// Declare your function here
function createLongGreeting(name, age) {
return `Hello, my name is ${name} and I'm ${age} years old`;
}

const greeting = createLongGreeting("Daniel", 30);
const greeting = createLongGreeting("Ibrahim", 24);

console.log(greeting);
console.log(greeting);
14 changes: 14 additions & 0 deletions exercises/L-functions-nested/exercise.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,17 @@ var mentor2 = "Irina";
var mentor3 = "Mimi";
var mentor4 = "Rob";
var mentor5 = "Yohannes";

function greeting(name) {
return `hello ${name}`;
}

function greetingUpperCase(name) {
return greeting(name).toUpperCase();
}

console.log(greetingUpperCase(mentor1));
console.log(greetingUpperCase(mentor2));
console.log(greetingUpperCase(mentor3));
console.log(greetingUpperCase(mentor4));
console.log(greetingUpperCase(mentor5));
18 changes: 11 additions & 7 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(price) {
return price * 1.4;
}

/*
CURRENCY CONVERSION
Expand All @@ -15,7 +17,9 @@ 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(currency) {
return currency * 0.99 * 5.7;
}

/* ======= TESTS - DO NOT MODIFY =====
There are some Tests in this file that will help you work out if your code is working.
Expand All @@ -25,17 +29,17 @@ To run these tests type `npm run extraTo run the tests for just this one file, t
*/

test("convertToUSD function works for £32", () => {
expect(convertToUSD(32)).toEqual(44.8);
expect(convertToUSD(32)).toEqual(44.8);
});

test("convertToUSD function works for £50", () => {
expect(convertToUSD(50)).toEqual(70);
expect(convertToUSD(50)).toEqual(70);
});

test("convertToBRL function works for £30", () => {
expect(convertToBRL(30)).toEqual(169.29);
expect(convertToBRL(30)).toEqual(169.29);
});

test("convertToBRL function works for £1.50", () => {
expect(convertToBRL(1.5)).toEqual(8.46);
});
expect(convertToBRL(1.5)).toEqual(8.46);
});
45 changes: 23 additions & 22 deletions extra/2-piping.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,58 +16,59 @@
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 =
// its not reusable
let badCode = "£" + (startingValue + 10) * 2;

/* BETTER PRACTICE */

let goodCode =

let addNum = add(startingValue, 10);
let multiplyNum = multiply(addNum, 2);
let goodCode = format(multiplyNum);
/* ======= TESTS - DO NOT MODIFY =====
There are some Tests in this file that will help you work out if your code is working.
There are some Tests in this file that will help you work out if your code is working.

To run these tests type `npm run extraTo run the tests for just this one file, type `npm run extra-tests -- --testPathPattern 2-piping` into your terminal
(Reminder: You must have run `npm install` one time before this will work!)
*/
To run these tests type `npm run extraTo run the tests for just this one file, type `npm run extra-tests -- --testPathPattern 2-piping` into your terminal
(Reminder: You must have run `npm install` one time before this will work!)
*/

test("add function - case 1 works", () => {
expect(add(1, 3)).toEqual(4);
expect(add(1, 3)).toEqual(4);
});

test("add function - case 2 works", () => {
expect(add(2.4, 5)).toEqual(7.4);
expect(add(2.4, 5)).toEqual(7.4);
});

test("multiply function works", () => {
expect(multiply(2, 3)).toEqual(6);
expect(multiply(2, 3)).toEqual(6);
});

test("format function works for whole number", () => {
expect(format(16)).toEqual("£16");
expect(format(16)).toEqual("£16");
});

test("format function works for decimal number", () => {
expect(format(10.1)).toEqual("£10.1");
expect(format(10.1)).toEqual("£10.1");
});

test("badCode variable correctly assigned", () => {
expect(badCode).toEqual("£24");
expect(badCode).toEqual("£24");
});

test("goodCode variable correctly assigned", () => {
expect(goodCode).toEqual("£24");
});
expect(goodCode).toEqual("£24");
});
22 changes: 11 additions & 11 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) {
return 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 All @@ -26,15 +26,15 @@ 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);
expect(addNumbers(3, 4, 6)).toEqual(13);
});

test("introduceMe function returns the correct string", () => {
expect(introduceMe("Sonjide", 27)).toEqual(
"Hello, my name is Sonjide and I am 27 years old"
);
expect(introduceMe("Sonjide", 27)).toEqual(
"Hello, my name is Sonjide and I am 27 years old"
);
});

test("getTotal returns a string describing the total", () => {
expect(getTotal(23, 5)).toEqual("The total is 28");
});
expect(getTotal(23, 5)).toEqual("The total is 28");
});
Loading