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
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(78967868678);

console.log("Hello World.I just started learning JavaScript!");
6 changes: 5 additions & 1 deletion 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`

var greeting = "Hello world";

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

You should avoid var. As mentioned last week, prefer using let or const. var is old, has tricky semantics, and is no longer needed.

console.log(greeting);
console.log(greeting);
console.log(greeting);
console.log(greeting);
console.log(greeting);
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 = "This is a string";
var messageType = typeof message;
console.log(message);
console.log(messageType);
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`
var greetingStart = "Hello, my name is ";
var name1 = "Oleks. ";
var you = "And you ? "
var greeting = greetingStart + name1 + you;

console.log(message);
console.log(greeting);
24 changes: 23 additions & 1 deletion exercises/F-strings-methods/exercise.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,25 @@
// Start by creating a variable `message`

var name1 = "Oleks";
var nameLength = name1.length;
var introduce1 = " My name is Oleks and my name is ";
var introduce2 = "characters long.";
var message = introduce1 + nameLength + " " + introduce2;
console.log(message);
// second way
var name1 = "Oleks";
var nameLength = name1.length;
var introduce1 = " My name is ";
var introduce3 = "and my name is ";
var introduce2 = "characters long.";
var message = introduce1 + name1 + " "+ introduce3 +
nameLength + " " + introduce2;
console.log(message);
// trim method
var name1 = "Oleks";
var nameLength = name1.length;
var introduce1 = " My name is ";
var introduce3 = "and my name is ";
var introduce2 = "characters long.";
var message =
introduce1 + name1 + " " + introduce3 + nameLength + " " + introduce2;
console.log(message.trim());

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!

17 changes: 17 additions & 0 deletions exercises/F-strings-methods/exercise2.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,20 @@
const name = " Daniel ";

var name1 = "Oleks";
var nameLength = name1.length;
var introduce1 = " My name is ";

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Why all the whitespace at the start?

var introduce3 = "and my name is ";
var introduce2 = "characters long.";
var message =
introduce1 + name1 + " " + introduce3 + nameLength + " " + introduce2;
console.log(message);
// trim method
var name1 = "Oleks";
var nameLength = name1.length;
var introduce1 = " My name is ";
var introduce3 = "and my name is ";
var introduce2 = "characters long.";
var message =
introduce1 + name1 + " " + introduce3 + nameLength + " " + introduce2;
console.log(message.trim());

11 changes: 11 additions & 0 deletions exercises/G-numbers/exercise.js
Original file line number Diff line number Diff line change
@@ -1 +1,12 @@
// Start by creating a variables `numberOfStudents` and `numberOfMentors`
var numberOfStudents = 50;
var numberOfMentors = 10;
var stud = "Number of students: ";
console.log(stud + numberOfStudents);
var ment = "Number of mentors: ";
console.log(ment + numberOfMentors);
var total = "Total number of students and mentors: ";
var sum = numberOfMentors + numberOfStudents;

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Great 👍

console.log(total + sum);


27 changes: 27 additions & 0 deletions exercises/I-floats/exercise.js
Original file line number Diff line number Diff line change
@@ -1,2 +1,29 @@
var numberOfStudents = 15;
var numberOfMentors = 8;
var preciseAge = 30.612437;
varroughAge = Math.round(preciseAge); // 30
console.log(varroughAge);

//from G ex + new solution

var stud = "Number of students: ";
console.log(stud + numberOfStudents);
var ment = "Number of mentors: ";
console.log(ment + numberOfMentors);
var total = "Total number of students and mentors: ";
var sum = numberOfMentors + numberOfStudents;
console.log(total + sum);
var percentageStudents = 100*numberOfStudents/sum

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Don' forget the ; at the end of the line. Even if it won't change the behaviour of your code, it's better to stay consistent.

var percentageMentors = 100*numberOfMentors/sum
var roundStudents = Math.round(percentageStudents);
var roundMentors = Math.round(percentageMentors);

console.log("Percentage mentors: " + roundMentors + " %.");
console.log("Percentage students: " + roundStudents + " %.");
// Result
// 31
// Number of students: 15
// Number of mentors: 8
// Total number of students and mentors: 23
// Percentage mentors: 35 %.
// Percentage students: 65 %.
18 changes: 16 additions & 2 deletions exercises/J-functions/exercise.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,21 @@
function halve(number) {
// complete the function here
return number/2;
}

var result = halve(12);
console.log("result 12/2=", result);

console.log(result);
var result = halve(24);
console.log("result 24/2=", result);

var result = halve(100);
console.log("result 100/2=", result);

var result = halve(365);

console.log("result 365/2=", result);

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

var result = triple(12);

console.log(result);
console.log("result 12 x 3 = ", result);

// result 12 x 3 = 36
2 changes: 1 addition & 1 deletion exercises/K-functions-parameters/README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
The input given to a function is called a **parameter**.
"The input given to a function is called a **parameter**.

A function can take more than one parameter:

Expand Down
6 changes: 3 additions & 3 deletions exercises/K-functions-parameters/exercise.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
// Complete the function so that it takes input parameters
function multiply() {
// Calculate the result of the function and return it
function multiply(a, b) {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Perfect

return a * b;
}

// Assign the result of calling the function the variable `result`
var result = multiply(3, 4);

console.log(result);
console.log("result 3*4 = ", result);
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;

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

The indentation of this line is 4 characters, while you use 1 above in your code. Again, for the sake of consistency and readability, always use the same amount.

}
var result = divide(3, 4);

console.log(result);
console.log("a / b = ", result);
7 changes: 5 additions & 2 deletions 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");

console.log(greeting);

// Hello, my name is Daniel
8 changes: 5 additions & 3 deletions exercises/K-functions-parameters/exercise4.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
// Declare your function first

function summ(a, b) {
return a + b
}
// Call the function and assign to a variable `sum`

console.log(sum);
var sum = summ(13, 124);
console.log("13 + 124 = ", sum);
8 changes: 7 additions & 1 deletion exercises/K-functions-parameters/exercise5.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
// Declare your function here

function createLongGreeting(name, age) {
return ("Hello, my name is " + name + " and I am "
+ age + " years old")
}
const greeting = createLongGreeting("Daniel", 30);

console.log(greeting);


// Hello, my name is Daniel and I am 30 years old
16 changes: 16 additions & 0 deletions exercises/L-functions-nested/exercise.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,19 @@ var mentor2 = "Irina";
var mentor3 = "Mimi";
var mentor4 = "Rob";
var mentor5 = "Yohannes";

function shoutyGreeting(mentor) {
return ("HELLO," + " " + mentor.toUpperCase() + " !")
}
console.log(shoutyGreeting(mentor1));
console.log(shoutyGreeting(mentor2));
console.log(shoutyGreeting(mentor3));
console.log(shoutyGreeting(mentor4));
console.log(shoutyGreeting(mentor5));

// Result a shouty greeting to each one mentors:
// HELLO, DANIEL !
// HELLO, IRINA !
// HELLO, MIMI !
// HELLO, ROB !
// HELLO, YOHANNES !
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,11 @@
Write a function that converts a price to USD (exchange rate is 1.4 $ to £)
*/

function convertToUSD() {}
function convertToUSD(price) {

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 think you meant pricePound here.
Otherwise it's good idea to use the currency in the name of the variable or parameter. Same with units: distanceInMeters, waveLengthCm, etc. It can be useful to avoid any confusion when sharing your code.

let dol = (price*1.4).toFixed(2);
return Number(dol);
}


/*
CURRENCY CONVERSION
Expand All @@ -15,7 +19,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 Number((price*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
19 changes: 11 additions & 8 deletions extra/2-piping.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,26 +16,29 @@
the final result to the variable goodCode
*/

function add() {

function add(number1, number2) {
return number1 + number2;
}

function multiply() {

function multiply(number1, number2) {
return number1 * number2;
}

function format() {

function format(n) {
return "£" + n;
}

const startingValue = 2;

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

/* BETTER PRACTICE */

let goodCode =
let sum = add(startingValue, 10);
let multiplies = multiply(sum, startingValue);
let formNumber = format(multiplies);
let goodCode = formNumber;

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