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
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);
12 changes: 10 additions & 2 deletions exercises/D-strings/exercise.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
// Start by creating a variable `message`

console.log(message);
// ## Exercise

// - Write a program that logs a message with a greeting and your name

let message = "Merry Christmas!!!"

let myVariableType = "This is a " + typeof message;


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

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

console.log(message);
// - Log a message that includes the length of your name

var myName = "Daniel";
var lengthOfMyName = myName.length;
var message = "My name is " + myName + " and my name is " + lengthOfMyName + "character long.";

console.log(message);
10 changes: 9 additions & 1 deletion exercises/F-strings-methods/exercise2.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
const name = " Daniel ";
// ## Exercise 2

// - Log the same message using the variable, `name` provided
// - Use the `.trim` method to remove the extra whitespace

const myName = " Daniel ";
var lengthOfMyName = myName.length;

var message = "My name is " + myName.trim() + " and my name is " + lengthOfMyName + " character long.";

console.log(message);
18 changes: 18 additions & 0 deletions exercises/G-numbers/exercise.js
Original file line number Diff line number Diff line change
@@ -1 +1,19 @@
// ## Exercise

// - Create two variables `numberOfStudents` and `numberOfMentors`
// - Log a message that displays the total number of students and mentors

// ## Expected result

// ```
// Number of students: 15
// Number of mentors: 8
// Total numnber of students and mentors: 23

// Start by creating a variables `numberOfStudents` and `numberOfMentors`
var noOfStudents = 15;
var noOfMentors = 8;
var total = noOfStudents + noOfMentors
var message = "Total number of students and mentors: " + total;

console.log(message)
22 changes: 22 additions & 0 deletions exercises/I-floats/exercise.js
Original file line number Diff line number Diff line change
@@ -1,2 +1,24 @@

// ## Exercise

// - Using the variables provided in the exercise calculate the percentage of mentors and students in the group

// ## Expected result


// Percentage students: 65%
// Percentage mentors: 35%




var numberOfStudents = 15;
var numberOfMentors = 8;

var total = numberOfMentors + numberOfStudents;

var studentsPercentage = Math.round((numberOfStudents/total)*100);
var mentorsPercentage = Math.round((numberOfMentors/total)*100);

console.log("Percentage students: " + studentsPercentage + "%");
console.log("Percentage mentors: " + mentorsPercentage + "%");
13 changes: 12 additions & 1 deletion exercises/J-functions/exercise.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,16 @@
// Exercise

// - Complete the function in exercise.js so that it halves the input
// - Try calling the function more than once with some different numbers

// > Remember to use the return keyword to get a value out of the function

// Expected result
// 6


function halve(number) {
// complete the function here
return number/2
}

var result = halve(12);
Expand Down
10 changes: 9 additions & 1 deletion exercises/J-functions/exercise2.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
// Exercise 2

// - Complete the function in exercise2.js so that it triples the input

// ## Expected result
// 36


function triple(number) {
// complete function here
return number * 3;
}

var result = triple(12);
Expand Down
5 changes: 3 additions & 2 deletions exercises/K-functions-parameters/exercise.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@

// Complete the function so that it takes input parameters
function multiply() {
// Calculate the result of the function and return it
function multiply(a, b) {
return a * b
}

// Assign the result of calling the function the variable `result`
Expand Down
4 changes: 3 additions & 1 deletion 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(a, b) {
return a/b;
}
var result = divide(3, 4);

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

var greeting = createGreeting("Daniel");

Expand Down
14 changes: 14 additions & 0 deletions exercises/K-functions-parameters/exercise4.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,19 @@
// Exercise 4

// - Write a function that adds two numbers together
// - Call the function, passing `13` and `124` as parameters, and assigning the returned value to a variable `sum`

// ## Expected result
// 137


// Declare your function first
function add(a, b) {
return a + b;
}


// Call the function and assign to a variable `sum`
var sum = add(13, 124)

console.log(sum);
11 changes: 11 additions & 0 deletions exercises/K-functions-parameters/exercise5.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,16 @@
//Exercise 5

// - Write a function that takes a name (a string) and an age (a number) and returns a greeting (a string)
// ## Expected result
// Hello, my name is Daniel and I'm 30 years old

// Declare your function here

function createLongGreeting(userName, userAge) {
return `Hello, my name is ${userName} and I'm ${userAge} years old`
}


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

console.log(greeting);
41 changes: 41 additions & 0 deletions exercises/L-functions-nested/exercise.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,46 @@
// - In `exercise.js` you have been provided with the names of some mentors. Write a program that logs a shouty greeting to each one.
// - Your program should include a function that spells their name in uppercase, and a function that creates a shouty greeting.
// - Log each greeting to the console.

// ## Expected result

// ```
// HELLO DANIEL
// HELLO IRINA
// HELLO MIMI
// HELLO ROB
// HELLO YOHANNES




function createShoutyMessage(name) {
var largeName = makeCapital(name);
return "HELLO " + largeName;
}
function makeCapital(str) {
return str.toUpperCase();
}


var mentor1 = "Daniel";
var mentor2 = "Irina";
var mentor3 = "Mimi";
var mentor4 = "Rob";
var mentor5 = "Yohannes";



const greetMentor1 = createShoutyMessage(mentor1);
const greetMentor2 = createShoutyMessage(mentor2);
const greetMentor3 = createShoutyMessage(mentor3);
const greetMentor4 = createShoutyMessage(mentor4);
const greetMentor5 = createShoutyMessage(mentor5);

console.log(greetMentor1)
console.log(greetMentor2)
console.log(greetMentor3)
console.log(greetMentor4)
console.log(greetMentor5)


10 changes: 8 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(gbp) {
var usd = gbp * 1.4
return usd
}

/*
CURRENCY CONVERSION
Expand All @@ -15,7 +18,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(gbp) {
const brlAfterFees = parseFloat(((gbp*0.99)*5.7).toFixed(2));
return brlAfterFees;
}

/* ======= TESTS - DO NOT MODIFY =====
There are some Tests in this file that will help you work out if your code is working.
Expand Down
27 changes: 19 additions & 8 deletions extra/2-piping.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,26 +16,37 @@
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(a) {
return '£' + a.toString()
}

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))
//Answer : It is bad practice because the function is very difficult for any other programmer to understand. Code should be written such simple format that is simple to read and understand.

/* BETTER PRACTICE */

let goodCode =

let addedValue = add(startingValue, 10);
let multipliedValue = multiply(addedValue, 2);
let formattedFinalValue = format(multipliedValue)
let goodCode = formattedFinalValue;


//Answer: this is goodCode because the code is much simpler to read and understand.


/* ======= TESTS - DO NOT MODIFY =====
There are some Tests in this file that will help you work out if your code is working.
Expand Down
Loading