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 README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ The files for the mandatory/extra exercises are intended to be run as jest tests
- To run the tests for all mandatory/extra exercises, run `npm test`
- To run only the tests for the mandatory exercises, run `npm test -- --selectProjects mandatory`
- To run only the tests for the extra exercises, run `npm test -- --selectProjects extra`
- To run a single exercise/test (for example `mandatory/1-writer.js`), run `npm test -- --testPathPattern mandatory/1-writer.js` (Remember, you can use tab-completion to get files relative to the current directory, so m`Tab ↹`/1-`Tab ↹` will autocomplete get you the test file starting with 1-)
- To run a single exercise/test (for example `mandatory/1-writer.js`), run ``npm test -- --testPathPattern mandatory/1-writer.js (Remember, you can use tab-completion to get files relative to the current directory, so m`Tab ↹`/1-`Tab ↹` will autocomplete get you the test file starting with 1-)

For more information about tests, look here:

Expand Down
3 changes: 3 additions & 0 deletions exercises/B-hello-world/exercise.js
Original file line number Diff line number Diff line change
@@ -1 +1,4 @@
console.log("Hello world");
console.log("I've just started to learn JavaScript");
console.log(500);

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Very good start. JavaScript can be challenging and with practice we will get better.

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);
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 string";
let messageType = typeof message;

console.log(message);
console.log(messageType);
4 changes: 4 additions & 0 deletions 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 messageStart = "Hello, my name is ";
let myName = "Helen";

let message = messageStart + myName;

console.log(message);
10 changes: 10 additions & 0 deletions exercises/F-strings-methods/exercise.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,13 @@
// Start by creating a variable `message`
const myName = "Helen";
const myNameLength = myName.length;
const message =
"Hello, my name is " +
myName +
" and my name is " +
myNameLength +
" characters long.";

console.log(myName);
console.log(myNameLength);
console.log(message);
12 changes: 11 additions & 1 deletion exercises/F-strings-methods/exercise2.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,13 @@
const name = " Daniel ";
let myName = " Helen ";
let myNameTrimmed = myName.trim();
let myNameLength = myNameTrimmed.length;
let message =
"Hello, my name is " +
myNameTrimmed +
" and my name is " +
myNameLength +
" characters long.";

console.log(myNameLength);
console.log(myNameTrimmed);
console.log(message);
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 = 50;
let numberOfMentors = 25;
let total = numberOfStudents + numberOfMentors;
let message = "Total number of students and mentors: " + total;

console.log(message);
13 changes: 11 additions & 2 deletions exercises/I-floats/exercise.js
Original file line number Diff line number Diff line change
@@ -1,2 +1,11 @@
var numberOfStudents = 15;
var numberOfMentors = 8;
let numberOfStudents = 15;
let numberOfMentors = 8;
let total = numberOfStudents + numberOfMentors;
let percentOfStudents = (numberOfStudents * 100) / total;
let roundPercentStudents = Math.round(percentOfStudents);
let percentOfMentors = (numberOfMentors * 100) / total;
let roundPercentMentors = Math.round(percentOfMentors);

console.log(roundPercentStudents);

console.log(roundPercentMentors);
3 changes: 2 additions & 1 deletion 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
return number / 2;
}

var result = halve(12);
let result = halve(34);

console.log(result);
3 changes: 2 additions & 1 deletion 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
return number * 3;
}

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

console.log(result);
5 changes: 3 additions & 2 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(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);
let result = multiply(3, 4);

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(num1, num2) {
return num1 / num2;
}

var result = divide(3, 4);
let result = divide(3, 4);

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");
let greeting = createGreeting("Daniel");

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

function add(num1, num2) {
return num1 + num2;
}

let sum = add(13, 124);

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

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

34 changes: 29 additions & 5 deletions exercises/L-functions-nested/exercise.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,29 @@
var mentor1 = "Daniel";
var mentor2 = "Irina";
var mentor3 = "Mimi";
var mentor4 = "Rob";
var mentor5 = "Yohannes";
var mentor1 = "Daniel";
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

There's some indentation issues in the file -- basically, everything should start from the very left side, unless it's inside function brackets, or a for loop (you'll learn about these later) or something of this sort.

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

function helloGreeting(name) {
return name;
}
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 doesn't do anything as is -- all the work is being done by the other function. As per instructions, you should have:

  • One function that returns the name in all caps
  • One function that prints "HELLO "
    Note, the second function should call your first function to achieve its goal. See how it's used for age in the example in the readme for this exercise.

function upperCaseGreeting(helloGreeting) {
return ("Hello " + helloGreeting).toUpperCase();
}

var greeting = helloGreeting;
var shoutyGreeting = upperCaseGreeting;
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 is just renaming the function -- is this what you intended to do?



// console.log(greeting(mentor1));
// console.log(greeting(mentor2));
// console.log(greeting(mentor3));
// console.log(greeting(mentor4));
// console.log(greeting(mentor5));

console.log(shoutyGreeting(mentor1));
console.log(shoutyGreeting(mentor2));
console.log(shoutyGreeting(mentor3));
console.log(shoutyGreeting(mentor4));
console.log(shoutyGreeting(mentor5));

25 changes: 23 additions & 2 deletions extra/1-currency-conversion.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,18 @@
The business is breaking out into a new market and need to convert prices to USD
Write a function that converts a price to USD (exchange rate is 1.4 $ to £)
*/
function convertToUSD(pound) {
let usd = pound * 1.4;
return usd;
// return "$" + pound * 1.4.toFixed(2);
}

function convertToUSD() {}
// function convertToUSD(amountInPounds) {
// const exchangeRate = 1.4;
// return amountInPounds * exchangeRate;
// } // suggested in 'solutions'

// console.log(convertToUSD(200));

/*
CURRENCY CONVERSION
Expand All @@ -15,8 +25,19 @@ 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(pound) {
let brl = parseFloat(((pound / 100) * 99 * 5.7).toFixed(2));
return brl;
}

// function convertToBRL(amountInPounds) {
// const transactionFee = 0.01;
// const exchangeRate = 5.7;
// const amountAfterFee = amountInPounds * (1 - transactionFee);
// return amountAfterFee * exchangeRate;
// } //suggested in 'solutions'

// console.log(convertToBRL(10));
/* ======= TESTS - DO NOT MODIFY =====
There are some Tests in this file that will help you work out if your code is working.

Expand Down
38 changes: 32 additions & 6 deletions extra/2-piping.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,26 +16,52 @@
the final result to the variable goodCode
*/

function add() {

function add(a, b) {
return a + b;
}

function multiply() {
console.log(add(20, 9));

function multiply(a, b) {
return a * b;
}

function format() {
console.log(multiply(2, 10));

function format(num) {
return "£" + eval(num);
}

console.log(format(45));

const startingValue = 2;
function badPractice() {
return badCode;
}

let badCode = "£" + (startingValue + 10) * 2;

console.log(badPractice());

let incrementedValue = startingValue + 10;
let doubledValue = incrementedValue * 2;
let formattedValue = "£" + doubledValue;

function goodPractice() {
return goodCode;
}

let goodCode = formattedValue;

// let goodCode = format(multiply(add(startingValue, 10), 2)); //suggested in 'solutions'

// Why can this code be seen as bad practice? Comment your answer.
let badCode =

// Const should be used for the values we don't re-assign. The name startingValue suggests otherwise

/* BETTER PRACTICE */

let goodCode =
// let 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
Loading