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

let greeting = '1';

//console.log(22);
console.log(greeting);
console.log(greeting);
console.log(greeting);
//console.log("Hi World!");

4 changes: 4 additions & 0 deletions exercises/C-variables/exercise.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
// Start by creating a variable `greeting`

let greeting = "Hello world";

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

let message = [] ;

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

I know this test passed, but I would normally expect message to be a string and not an array.

//let messageType = typeof message;

console.log(message);
console.log(typeof message);
3 changes: 3 additions & 0 deletions 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`
//let messageStart = "Hello, my name is ";
let messageName = "Daniel";
let message = "Hello, my name is " + messageName

console.log(message);
6 changes: 6 additions & 0 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`

const name = "Daniel";
//let messageLength = messageName.length

//let message = "My name is Daniel and my name is " + messageLength + " characters long";
let message = `My name is ${name} and my name is ${name.length} characters long`;

Copy link
Copy Markdown

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!


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

const name = " Johnson ";
//const trimName = Name.trim();
//let nameLength = trimName.length;

//let message = "My name is " + trimName + " and my name is "+ nameLength + " characters long"

let message = `My name is ${name.trim()} and my name is ${(name.trim().length)} characters long`;

console.log(message);
2 changes: 1 addition & 1 deletion exercises/G-numbers/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ Unlike strings, numbers do not need to be wrapped in quotes.
var age = 30;
```

You can use mathematical operators to caclulate numbers:
You can use mathematical operators to calculate numbers:

```js
var sum = 10 + 2; // 12
Expand Down
12 changes: 12 additions & 0 deletions exercises/G-numbers/exercise.js
Original file line number Diff line number Diff line change
@@ -1 +1,13 @@
// Start by creating a variables `numberOfStudents` and `numberOfMentors`
let numberOfStudents = 15;
let numberOfMentors = 10;

let totalNum = numberOfStudents + numberOfMentors;

//console.log("Number of students: "+ numberOfStudents);
//console.log("Number of mentors: " + numberOfMentors);
//console.log("Total number of students and mentors: "+ totalNum);

console.log(`Number of students: ${numberOfStudents}`);
console.log(`Number of mentors: ${numberOfMentors}`);
console.log(`Total number of students and mentors: ${totalNum}`);
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 totalNum = numberOfStudents + numberOfMentors;

let studentPercentage = (numberOfStudents / totalNum) * 100;
let mentorPercentage = (numberOfMentors / totalNum) * 100;

console.log(`Percentage students: ${Math.round(studentPercentage)}%`);
console.log(`Percentage mentors: ${Math.round(mentorPercentage)}%`);

//console.log("Percentage students: "+Math.round(studentPercentage)+"%");
//console.log("Percentage mentors: " +Math.round(mentorPercentage)+"%");
10 changes: 9 additions & 1 deletion exercises/J-functions/exercise.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,15 @@
function halve(number) {
// complete the function here
return number / 2;
}

var result = halve(12);
let result = halve(12);
// let res2 = halve (88);
// let res3 = halve (100);

console.log(result);

console.log(halve(88));
console.log(halve(122));


5 changes: 4 additions & 1 deletion exercises/J-functions/exercise2.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
function triple(number) {
// complete function here
return number * 3
}

var result = triple(12);
let result = triple(12);

console.log(result);


9 changes: 5 additions & 4 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() {
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);
let result = multiply(3, 4);

console.log(result);

6 changes: 5 additions & 1 deletion exercises/K-functions-parameters/exercise2.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
// Declare your function first

var result = divide(3, 4);
function divide(a,b) {
return a / b;
}
let result = divide(3, 4);

console.log(result);

7 changes: 6 additions & 1 deletion exercises/K-functions-parameters/exercise3.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
// Write your function here

var greeting = createGreeting("Daniel");
function createGreeting(name){
// return "Hello, my name is " + name;
return `Hello, my name is ${name}`;
}
let greeting = createGreeting("Daniel");

console.log(greeting);

6 changes: 5 additions & 1 deletion exercises/K-functions-parameters/exercise4.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
// Declare your function first

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

console.log(sum);

6 changes: 5 additions & 1 deletion exercises/K-functions-parameters/exercise5.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
// Declare your function here

function createLongGreeting(str,age) {
//return "Hello, my name is " + str + " and I'm " + age + " years old";
return `Hello, my name is ${str} and I'm ${age} years old`;
}
const greeting = createLongGreeting("Daniel", 30);

console.log(greeting);

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 shoutyGreeting(){
console.log("HELLO " + mentor1.toUpperCase());
console.log("HELLO " + mentor2.toUpperCase());
console.log("HELLO " + mentor3.toUpperCase());
console.log("HELLO " + mentor4.toUpperCase());
console.log("HELLO " + mentor5.toUpperCase());

}

shoutyGreeting()




19 changes: 14 additions & 5 deletions extra/1-currency-conversion.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,26 @@
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
===================
The business is now breaking into the Brazilian market
Write a new function for converting to the Brazilian real (exchange rate is 5.7 BRL to £)
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.
Write a new function for converting to the Brazilian real (exchange rate is
5.7 BRL to £)
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 priceAfterFee = price * 0.99;
let priceInBRL = priceAfterFee * 5.7;
return Math.round(priceInBRL*100)/100;

//return Number(((poundmoney * 0.99)* 5.7).toFixed(2))
}

/* ======= TESTS - DO NOT MODIFY =====
There are some Tests in this file that will help you work out if your code is working.
Expand Down
29 changes: 16 additions & 13 deletions extra/2-piping.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,38 +4,41 @@
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
on one line (assign the result to the variable badCode):
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
- format it

3. Write a more readable version of what you wrote in step 2 under the BETTER PRACTICE comment. Assign
the final result to the variable goodCode
3. Write a more readable version of what you wrote in step 2 under the BETTER
PRACTICE comment. Assign 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;
}

const startingValue = 2;

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

/* BETTER PRACTICE */
let goodadd = add(startingValue,10);
let goodmultiply = multiply(2,goodadd);

let goodCode =
let goodCode = format(goodmultiply);

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

This looks great!


/* ======= TESTS - DO NOT MODIFY =====
There are some Tests in this file that will help you work out if your code is working.
Expand Down
9 changes: 7 additions & 2 deletions extra/3-magic-8-ball.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,12 @@

// This should log "The ball has shaken!"
// and return the answer.
function shakeBall() {
function shakeBall(answer) {
//Write your code in here
if ( answer === positive ) {

console.log("The ball has shaken " + answer );

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Here, only "The ball has shaken!" should be in the console log. The answer should be picked at random from the possible answers.

}
}

/*
Expand All @@ -56,7 +60,8 @@ function shakeBall() {
- negative
- very negative

This function should expect to be called with any value which was returned by the shakeBall function.
This function should expect to be called with any value which was returned
by the shakeBall function.
*/
function checkAnswer(answer) {
//Write your code in here

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

This function should take any of the possible random answers and then return if the answer is very positive, positive, negative or very negative.

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

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

return "The total is total";
let total = a + b;
return `The total is ${total}`;
//return "The total is " + total;
}

/*
Expand Down
8 changes: 4 additions & 4 deletions mandatory/2-logic-error.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
// 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
4 changes: 4 additions & 0 deletions mandatory/3-function-output.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,20 @@
// Add comments to explain what this function does. You're meant to use Google!
function getRandomNumber() {
return Math.random() * 10;
// Math.random() method returns a random floating-point number between 0.0 and 1.0.
// This can be used to generate random number.
}

// Add comments to explain what this function does. You're meant to use Google!
function combine2Words(word1, word2) {
return word1.concat(word2);
// .concat() method returns a string containing all the string values in a node-set concatenated together.
}

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
}

/*
Expand Down
Loading