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
14 changes: 7 additions & 7 deletions exercises/B-hello-world/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@ Inside of `exercise.js` there's a line of code that will print "Hello world!".

### 1. Run the program

* Open a terminal window
* Change directory to this folder (`cd B-hello-world`)
* Run the program using node (`node exercise.js`)
- Open a terminal window
- Change directory to this folder (`cd B-hello-world`)
- Run the program using node (`node exercise.js`)

### 2. Experiment

* Try to `console.log()` something different. For example, 'Hello World. I just started learning JavaScript!'.
* Try to console.log() several things at once.
* What happens when you get rid of the quote marks?
* What happens when you console.log() just a number without quotes?
- Try to `console.log()` something different. For example, 'Hello World. I just started learning JavaScript!'.
- Try to console.log() several things at once.
- What happens when you get rid of the quote marks? Syntax error
- What happens when you console.log() just a number without quotes? It prints the number
3 changes: 2 additions & 1 deletion exercises/B-hello-world/exercise.js
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
console.log("Hello world");
console.log("Hello World. I just started learning JavaScript!");
console.log(2);
4 changes: 2 additions & 2 deletions exercises/C-variables/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ The program above will print "Hello world" to the console. Notice how it uses th

## Exercise

* Add a variable `greeting` to exercise.js (make sure it comes _before_ the console.log)
* Print your `greeting` to the console 3 times
- Add a variable `greeting` to exercise.js (make sure it comes _before_ the console.log)
- Print your `greeting` to the console 3 times

> Remember: to run this exercise you must change directory to the `D-variables`. If you already have a terminal window open for the previous exercise you can do this by running the command `cd ../D-variables`.

Expand Down
3 changes: 3 additions & 0 deletions exercises/C-variables/exercise.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
// Start by creating a variable `greeting`
const greeting = "Hello world";

console.log(greeting);
console.log(greeting);
console.log(greeting);
2 changes: 1 addition & 1 deletion exercises/D-strings/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ console.log(messageType); // logs 'string'

## Exercise

* Write a program that logs a message and its type
- Write a program that logs a message and its type

## Expected result

Expand Down
2 changes: 2 additions & 0 deletions 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`
const message = "This is a string";

console.log(message);
console.log(typeof message);
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 greetingStart = "Hello, my name is ";
let name = "Cecilia";

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

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

console.log(message);
console.log("My name is " + name + " and my name is " + name.length + " characters long");
2 changes: 1 addition & 1 deletion 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);
console.log("My name is " + name.trim() + " and my name is " + name.trim().length + " characters long");
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`
const numberOfStudents = 15;
const numberOfMentors = 8;

console.log("Number of students: " + numberOfStudents);
console.log("Number of mentors: " + numberOfMentors);
console.log("Total number of students and mentors: " + (numberOfMentors + numberOfStudents));
7 changes: 5 additions & 2 deletions exercises/I-floats/exercise.js
Original file line number Diff line number Diff line change
@@ -1,2 +1,5 @@
var numberOfStudents = 15;
var numberOfMentors = 8;
const numberOfStudents = 15;
const numberOfMentors = 8;

console.log("Percentage students: " + Math.round(numberOfStudents/(numberOfStudents + numberOfMentors)*100)+"%");
console.log("Percentage mentors: " + Math.round(numberOfMentors/(numberOfStudents + numberOfMentors)*100)+"%");
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
return number/2;
}

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

let result1 = halve(15);

console.log(result);
console.log(result1);
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(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);
const 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(a, b) {
return a/b;
}

var result = divide(3, 4);
const 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(greet) {
return "Hello, my name is " + greet;
}

var greeting = createGreeting("Daniel");
const greeting = createGreeting("Daniel");

console.log(greeting);
5 changes: 4 additions & 1 deletion 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 addition(a,b) {
return a + b;
}
// Call the function and assign to a variable `sum`
let sum = addition(13, 124);

console.log(sum);
4 changes: 3 additions & 1 deletion 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);
21 changes: 16 additions & 5 deletions exercises/L-functions-nested/exercise.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,16 @@
var mentor1 = "Daniel";
var mentor2 = "Irina";
var mentor3 = "Mimi";
var mentor4 = "Rob";
var mentor5 = "Yohannes";
let students = { "type": "students", "number": 15};
let mentors = { "type": "mentors", "number": 8};

function calculatePercentage(a,b) {
return Math.round(a.number / (a.number + b.number) * 100);
}

function createMessage(cat1, cat2) {
return "Percentage " + cat1.type + ": " + calculatePercentage(cat1, cat2) + "%";
}

let percentageOfStudents = createMessage(students, mentors);
let percentageOfMentors = createMessage(mentors, students);

console.log(percentageOfStudents);
console.log(percentageOfMentors);
19 changes: 19 additions & 0 deletions exercises/L-functions-nested/exercise2.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
let mentor1 = "Daniel";
let mentor2 = "Irina";
let mentor3 = "Mimi";
let mentor4 = "Rob";
let mentor5 = "Yohannes";

function shoutName(name) {
return name.toUpperCase();
}

function shoutGreeting(mentor) {
return "HELLO " + shoutName(mentor);
}

console.log(shoutGreeting(mentor1));
console.log(shoutGreeting(mentor2));
console.log(shoutGreeting(mentor3));
console.log(shoutGreeting(mentor4));
console.log(shoutGreeting(mentor5));
8 changes: 6 additions & 2 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 FORMATTING
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(price) {
return price * 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 Down
20 changes: 11 additions & 9 deletions extra/2-piping.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,26 +16,28 @@
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 =
// It is not clear what's going on for someone who is not familiar with the code.
let badCode = format(multiply(add(startingValue, 10), 2));

/* BETTER PRACTICE */

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

/* ======= 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