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 exercises/B-hello-world/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ We'll do this in JavaScript, using something called `console.log()`.

Inside of `exercise.js` there's a line of code that will print "Hello world!".

### 1. Run the program
### 1. Run the programcd

* Open a terminal window
* Change directory to this folder (`cd B-hello-world`)
Expand Down
4 changes: 3 additions & 1 deletion exercises/B-hello-world/exercise.js
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
console.log("Hello world");
console.log('Hello World. I just started learning JavaScript!. I love it.');
console.log(5);

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);
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
4 changes: 3 additions & 1 deletion 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`

var message = "I love Code Your Future";
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`
var greetingStart ="Hello, my name is";
var firstName = "Kos";
var message = greetingStart + " " + firstName;

console.log(message);
5 changes: 3 additions & 2 deletions 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`

console.log(message);
var name ="Kos";
var message = name.length;
console.log("My name is Kos and my name is" + " " + message + " " + "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 ";

var message = name.trim();
console.log(message);
4 changes: 4 additions & 0 deletions exercises/G-numbers/exercise.js
Original file line number Diff line number Diff line change
@@ -1 +1,5 @@
// Start by creating a variables `numberOfStudents` and `numberOfMentors`
let numberOfStudents = 15;
let numberOfMentors = 8;
let total = numberOfStudents + numberOfMentors;
console.log("Total number of students and mentors is:" + " " + total);
4 changes: 4 additions & 0 deletions exercises/I-floats/exercise.js
Original file line number Diff line number Diff line change
@@ -1,2 +1,6 @@
var numberOfStudents = 15;
var numberOfMentors = 8;
var percentage_1 = numberOfStudents / (numberOfStudents + numberOfMentors)*100;
var percentage_2 = numberOfMentors / (numberOfStudents + numberOfMentors)*100;
console.log("Percentage students:" + " " + Math.round(percentage_1) + "%");
console.log("Percentage mentors:" + " " + Math.round(percentage_2) + "%");
10 changes: 8 additions & 2 deletions exercises/J-functions/exercise.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
function halve(number) {
// complete the function here
return number / 2;
}

var result = halve(12);
var result_1 = halve(12);
var result_2 = halve(24);
var result_3 = halve(15);

console.log(result_1);
console.log(result_2);
console.log(result_3);

console.log(result);
9 changes: 7 additions & 2 deletions exercises/J-functions/exercise2.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
function triple(number) {
// complete function here
return number*3;
}

var result = triple(12);
var result_1 = triple(12);
var result_2 = triple(50);
var result_3 = triple(120);

console.log(result);
console.log(result_1);
console.log(result_2);
console.log(result_3);
12 changes: 6 additions & 6 deletions exercises/K-functions-parameters/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ function add(num1, num2) {

## Exercise

* Write a function that multiplies two numbers together
- Write a function that multiplies two numbers together

## Expected result

Expand All @@ -30,7 +30,7 @@ function add(num1, num2) {

## Exercise 2

* From scratch, write a function that divides two numbers
- From scratch, write a function that divides two numbers

## Expected result

Expand All @@ -40,7 +40,7 @@ function add(num1, num2) {

## Exercise 3

* Write a function that takes a name (a string) and returns a greeting
- Write a function that takes a name (a string) and returns a greeting

## Expected result

Expand All @@ -50,8 +50,8 @@ Hello, my name is Daniel

## 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`
- 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

Expand All @@ -61,7 +61,7 @@ Hello, my name is Daniel

## Exercise 5

* Write a function that takes a name (a string) and an age (a number) and returns a greeting (a string)
- Write a function that takes a name (a string) and an age (a number) and returns a greeting (a string)

## Expected result

Expand Down
3 changes: 2 additions & 1 deletion 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() {
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`
Expand Down
6 changes: 4 additions & 2 deletions 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);
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(name) {
return "Hello, my name is" + " " + name;
}

var greeting = createGreeting("Daniel");

Expand Down
4 changes: 4 additions & 0 deletions 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(x, y) {
return x + y;
}

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

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

Expand Down
8 changes: 8 additions & 0 deletions exercises/L-functions-nested/exercicise1.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
function participant(students, mentors) {
var percentStudents = students / (students + mentors)*100;
var percentMentors = mentors / (students + mentors)*100;
return "Percentage students:" + Math.round(percentStudents) + "%" + " " + " " + " " + "Percentage mentors:" + Math.round(percentMentors) + "%";

}
var result = participant(15, 8);
console.log(result);
63 changes: 63 additions & 0 deletions exercises/L-functions-nested/exercise.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,66 @@ var mentor2 = "Irina";
var mentor3 = "Mimi";
var mentor4 = "Rob";
var mentor5 = "Yohannes";

function nameToUppercase_1(mentor1) {
return mentor1.toUpperCase();
}
var writtenInUpperCase_1 = nameToUppercase_1("Daniel");
console.log(writtenInUpperCase_1);

function nameToUppercase_2(mentor2) {
return mentor2.toUpperCase();
}
var writtenInUpperCase_2 = nameToUppercase_2("Irina");
console.log(writtenInUpperCase_2);

function nameToUppercase_3(mentor3) {
return mentor3.toUpperCase();
}
var writtenInUpperCase_3 = nameToUppercase_3("Mimi");
console.log(writtenInUpperCase_3);

function nameToUppercase_4(mentor4) {
return mentor4.toUpperCase();
}
var writtenInUpperCase_4 = nameToUppercase_4("Rob");
console.log(writtenInUpperCase_4);

function nameToUppercase_5(mentor5) {
return mentor5.toUpperCase();
}
var writtenInUpperCase_5 = nameToUppercase_5("Yohannes");
console.log(writtenInUpperCase_5);


function createGreeting1(mentor1) {
return mentor1.toUpperCase();
}
var message1 ="HELLO" + " " + mentor1.toUpperCase();
console.log(message1);


function createGreeting2(mentor2) {
return mentor1.toUpperCase();
}
var message2 ="HELLO" + " " + mentor2.toUpperCase();
console.log(message2);

function createGreeting3(mentor3) {
return mentor3.toUpperCase();
}
var message3 ="HELLO" + " " + mentor3.toUpperCase();
console.log(message3);

function createGreeting4(mentor4) {
return mentor4.toUpperCase();
}
var message4 ="HELLO" + " " + mentor1.toUpperCase();
console.log(message4);


function createGreeting5(mentor5) {
return mentor5.toUpperCase();
}
var message5 ="HELLO" + " " + mentor1.toUpperCase();
console.log(message5);
11 changes: 9 additions & 2 deletions extra/1-currency-conversion.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,11 @@
Write a function that converts a price to USD (exchange rate is 1.4 $ to £)
*/

function convertToUSD() {}
function convertToUSD(price1) {
return price1 * 1.4;

}
convertToUSD(3.15);

/*
CURRENCY FORMATTING
Expand All @@ -15,7 +19,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(price2) {
return price2 * 5.7 * 99/100;
}
convertToBRL(30);

/* ======= TESTS - DO NOT MODIFY =====
There are some Tests in this file that will help you work out if your code is working.
Expand Down
21 changes: 16 additions & 5 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;

}
add(1, 3);

function multiply() {
function multiply(x, y) {
return x * y;

}
multiply(2, 3);

function format() {
function format(number) {
return "£" + number;

}
format(16);

const startingValue = 2

// Why can this code be seen as bad practice? Comment your answer.
let badCode =
let badCode = "£" + (startingValue + 10) * 2;

// This is bad practice because all written in one line and difficult to understand and possibly debugging.

/* BETTER PRACTICE */

let goodCode =
let adding = 10 + startingValue;
let timing = adding * 2;
let goodCode = "£" + timing;


/* ======= TESTS - DO NOT MODIFY =====
There are some Tests in this file that will help you work out if your code is working.
Expand Down
14 changes: 8 additions & 6 deletions mandatory/1-syntax-errors.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,20 @@
// 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" + " " + (a + b);

return "The total is total"

}

getTotal(23,5);

/*
===================================================
======= TESTS - DO NOT MODIFY BELOW THIS LINE =====
Expand Down
15 changes: 11 additions & 4 deletions mandatory/2-logic-error.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,24 @@
// 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();
}
trimWord(" CodeYourFuture ");


function getWordLength(word) {
return "word".length();
return word.length;
}
getWordLength("A wild sentence appeared!");




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

return a * b * c;
}
multiply(2, 3, 6);

/*
===================================================
Expand Down
Loading