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
13 changes: 13 additions & 0 deletions exercises/B-hello-world/exercise.js
Original file line number Diff line number Diff line change
@@ -1 +1,14 @@
console.log("Hello world");

// Try to `console.log()` something different. For example, 'Hello World. I just started learning JavaScript!'.
console.log("Hi, I'm Matilda, a software developer");

// Try to console.log() several things at once.
console.log("Hello " + "Everyone");
console.log("CodeYourFuture is " + "AWESOME!!!");

// What happens when you get rid of the quote marks? It reads it as a variable then throws an error that the variable hasn't been defined.
// console.log(hello);

// What happens when you console.log() just a number without quotes? It returns a number
console.log(99);
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`

let greeting = "Hello world";
console.log(greeting);
console.log(greeting);
console.log(greeting);
3 changes: 2 additions & 1 deletion exercises/D-strings/exercise.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// Start by creating a variable `message`

let message = "I think coding is very fun";
console.log(message);
console.log(typeof message);
5 changes: 3 additions & 2 deletions exercises/E-strings-concatenation/exercise.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// Start by creating a variable `message`

console.log(message);
let message = "Hey there, it's nice to meet you, I'm ";
let name = "Matilda";
console.log(message + name);
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 = "Matilda";
let length = name.length;
let message = `Hi, I'm ${name}, ${name} has ${length} characters in it`;
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 = `My name is ${name.trim()} and my name is 6 characters long`;
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 message = `Number of students: ${numberOfStudents}
Number of mentors: ${numberOfMentors}
Total number of students and mentors: ${numberOfStudents + numberOfMentors}`;
console.log(message);
11 changes: 11 additions & 0 deletions exercises/I-floats/exercise.js
Original file line number Diff line number Diff line change
@@ -1,2 +1,13 @@
var numberOfStudents = 15;
var numberOfMentors = 8;

let totalNumber = numberOfStudents + numberOfMentors;
let studentPercentage = Math.round((numberOfStudents / totalNumber) * 100);
let mentorPercentage = Math.round((numberOfMentors / totalNumber) * 100);

let numbers = `Percentage students: ${studentPercentage}%
Percentage mentors: ${mentorPercentage}%`;

console.log(numbers);
// Percentage students: 65%
// Percentage mentors: 35%
6 changes: 5 additions & 1 deletion exercises/J-functions/exercise.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
function halve(number) {
// complete the function here
// complete the function here
return number / 2;
}

var result = halve(12);

console.log(result);
console.log(halve(79));
console.log(halve(8990));
console.log(halve(787979323));
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(a, b) {
// Calculate the result of the function and return it
return a * b;
}

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

console.log(result);
console.log(result);
5 changes: 4 additions & 1 deletion exercises/K-functions-parameters/exercise2.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
// Declare your function first
function divide(a, b) {
return a / b;
}

var result = divide(3, 4);

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

var greeting = createGreeting("Daniel");

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

// Call the function and assign to a variable `sum`

console.log(sum);
let sum = sumOfNumbers(13, 124);
console.log(sum);
8 changes: 5 additions & 3 deletions exercises/K-functions-parameters/exercise5.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
// 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);

console.log(greeting);
// Hello, my name is Daniel and I'm 30 years old
console.log(greeting);
2 changes: 1 addition & 1 deletion exercises/L-functions-nested/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ function getAgeInDays(age) {
return age * 365;
}

function createCreeting(name, age) {
function createGreeting(name, age) {
var ageInDays = getAgeInDays(age);
var message =
"My Name is " + name + " and I was born over " + ageInDays + " days ago!";
Expand Down
15 changes: 15 additions & 0 deletions exercises/L-functions-nested/exercise.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,18 @@ var mentor2 = "Irina";
var mentor3 = "Mimi";
var mentor4 = "Rob";
var mentor5 = "Yohannes";

function upperCaseNames(mentor) {
return mentor.toUpperCase();
}

function shoutyGreeting(mentor) {
var name = upperCaseNames(mentor);
return "HELLO " + name;
}

console.log(shoutyGreeting(mentor1));
console.log(shoutyGreeting(mentor2));
console.log(shoutyGreeting(mentor3));
console.log(shoutyGreeting(mentor4));
console.log(shoutyGreeting(mentor5));
21 changes: 13 additions & 8 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,27 +17,30 @@ 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(price) {
let num = (price / 100) * 99 * 5.7; //converts £ to brl
return Math.round(num * 100 + Number.EPSILON) / 100; //returns the value as a 2dp number
}

/* ======= TESTS - DO NOT MODIFY =====
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 1-syntax-errors` into your terminal
To run the tests for just this one file, type `npm test -- --testPathPattern 1-currency-conversion` into your terminal
(Reminder: You must have run `npm install` one time before this will work!)
*/

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);
});
36 changes: 18 additions & 18 deletions extra/2-piping.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,27 +16,27 @@
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(num) {
return "£" + num;
}

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 sum = add(startingValue, 10);
let times = multiply(sum, 2);
let goodCode = format(times);
/* ======= TESTS - DO NOT MODIFY =====
There are some Tests in this file that will help you work out if your code is working.

Expand All @@ -45,29 +45,29 @@ To run these tests type `npm run extraTo run the tests for just this one file, t
*/

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");
});
Loading