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
6 changes: 6 additions & 0 deletions exercises/B-hello-world/exercise.js
Original file line number Diff line number Diff line change
@@ -1 +1,7 @@
// Various console.log messages at the same time
console.log("Hello world");
console.log(5); // Numbers on their own won't return errors as they are a different type of data
console.log("Hello World. I just started learning JavaScript!");
console.log("Returned to this exercise and changed this message!");
console.log("Sometimes I spent too long getting bored");
// Noticed that error messages appear on the terminal when words are not passed as strings (with quotation marks)
7 changes: 6 additions & 1 deletion exercises/C-variables/exercise.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
// Start by creating a variable `greeting`
// First tried the basic way: three separate times console.log(greeting); and then made a for-loop to try an alternative

console.log(greeting);
var greeting = "Aqui estoy!";

for (i = 0; i < 3; i++) {
console.log(greeting);
}
6 changes: 4 additions & 2 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`

console.log(message);
// Then another variable to store the data type and finally log it to the console
var message = "This is a string data type";
var messageType = typeof message;
console.log(messageType);
11 changes: 10 additions & 1 deletion exercises/E-strings-concatenation/exercise.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
// Start by creating a variable `message`

console.log(message);
// I tried this task first with variables in an individual form, but then decided to put them all in a function

function getGreeting(name) {
var greeting = "Hola";
var courtesy = ", ¿cómo estás hoy?";
var message = greeting + " " + name + courtesy;
return message;
}
var name = "Laurita";
console.log(getGreeting(name));
17 changes: 16 additions & 1 deletion exercises/F-strings-methods/exercise.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,18 @@
// Start by creating a variable `message`

console.log(message);
// I first tried it with variables (line 5, 6, 13) and then -after the functions exercises, made a function here too (lines 8 to 13)

// var myName = 'Laurita';
// var myGreeting = 'My name is ' + myName + ' and my name is ' + myName.length + ' characters long';

function getGreeting(name) {
var myGreeting =
"My name is " +
name +
" and my name is " +
name.length +
" characters long";
return myGreeting;
Comment on lines +9 to +15

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 Job! As a challenge, you can make use of template literals to tidy up the code and make it easier to read. This link: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Template_literals and video: https://youtu.be/NgF9-pdTDGs are quite useful - should you need them.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Thank you! It auto-formatted that way on save :-)

}
var name = "Laurita";
console.log(getGreeting(name));
10 changes: 10 additions & 0 deletions exercises/F-strings-methods/exercise2.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,13 @@
// There are two variables, one to store a name plus the other one to store a message
// The .trim() method was applied to the name to reduce the unnecessary whitespace

const name = " Daniel ";

const message =
" My name is " +
name.trim() +
" and my name is " +
name.trim().length +
" characters long";

console.log(message);
4 changes: 2 additions & 2 deletions 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 All @@ -25,5 +25,5 @@ var difference = 10 - 2; // 8
```
Number of students: 15
Number of mentors: 8
Total numnber of students and mentors: 23
Total number of students and mentors: 23
```
10 changes: 10 additions & 0 deletions exercises/G-numbers/exercise.js
Original file line number Diff line number Diff line change
@@ -1 +1,11 @@
// Start by creating a variables `numberOfStudents` and `numberOfMentors`

// Some variables were created to store numbers and a sentence, which then was logged to the console

let numberOfStudents = 30;
let numberOfMentors = 10;

let numberOfAdults =
"The total amount of adults is " + (numberOfStudents + numberOfMentors);

console.log(numberOfAdults);
2 changes: 1 addition & 1 deletion exercises/I-floats/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ Floats can be rounded to the nearest whole number using the `Math.round` functio

```js
var preciseAge = 30.612437;
var roughAge = Math.round(preciseAge); // 30
var roughAge = Math.round(preciseAge); // 31
```

## Exercise
Expand Down
15 changes: 15 additions & 0 deletions exercises/I-floats/exercise.js
Original file line number Diff line number Diff line change
@@ -1,2 +1,17 @@
var numberOfStudents = 15;
var numberOfMentors = 8;

// Variables created to generate the percentages and then the messages expected, which were then logged to the console

var numberOfAdults = numberOfMentors + numberOfStudents;

var percentageStudents = (numberOfStudents * 100) / numberOfAdults;
var percentageMentors = (numberOfMentors * 100) / numberOfAdults;

var totalStudents =
"Percentage of students: " + Math.round(percentageStudents) + "%";
var totalMentors =
"Percentage of mentors: " + Math.round(percentageMentors) + "%";

console.log(totalStudents);
console.log(totalMentors);
8 changes: 7 additions & 1 deletion 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
// Complete the function here
let half = number / 2;
return half;
}

var result = halve(12);

// Called the function various times

console.log(result);
console.log(halve(4));
console.log(halve(1458690980));
6 changes: 5 additions & 1 deletion exercises/J-functions/exercise2.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
function triple(number) {
// complete function here
// Completed function here to trebble a number and called it several times
let trebbledNum = number * 3;
return trebbledNum;
}

var result = triple(12);

console.log(result);
console.log(triple(39));
console.log(triple(1));
2 changes: 1 addition & 1 deletion exercises/K-functions-parameters/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ function add(a, b) {

When you write a function (sometimes called _declaring a function_) you assign names to the parameters inside of the parentheses (`()`). Parameters can be called anything.

This function is exactly the same as the on above:
This function is exactly the same as the one above:

```js
function add(num1, num2) {
Expand Down
4 changes: 3 additions & 1 deletion exercises/K-functions-parameters/exercise.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
// 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);

// Call the variable to show the value returned with the above function
console.log(result);
6 changes: 6 additions & 0 deletions exercises/K-functions-parameters/exercise2.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
// Declare your function first
function divide(num1, num2) {
// Write the block of code inside the curly braces
return num1 / num2;
}

// Store the value of this function on a variable
var result = divide(3, 4);

// Call the variable
console.log(result);
8 changes: 7 additions & 1 deletion exercises/K-functions-parameters/exercise3.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
// Write your function here
// Write your function here with the block of code inside the curly braces
function createGreeting(name) {
let myGreeting = "Hello, my name is " + name;
return myGreeting;
}

// Store the value in a variable
var greeting = createGreeting("Daniel");

// Call the variable
console.log(greeting);
9 changes: 6 additions & 3 deletions 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 mySum(num1, num2) {
let sum = num1 + num2;
return sum;
}
// Call the function and assign to a variable `sum`

console.log(sum);
let totalSum = mySum(13, 124);
console.log(totalSum);
10 changes: 9 additions & 1 deletion exercises/K-functions-parameters/exercise5.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
// Declare your function here
function myGreeting(name, age) {
let myName = "Hello, my name is " + name;
let myAge = " and I am " + age + " years old.";
let fullGreeting = myName + myAge;
return fullGreeting;
}

const greeting = createLongGreeting("Daniel", 30);
// Store the value in a variable
const greeting = myGreeting("Daniel", 30);

// Call the variable
console.log(greeting);
17 changes: 16 additions & 1 deletion exercises/L-functions-nested/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,22 @@ function createCreeting(name, age) {

## Exercise 1

- In `exercise.js` you have been provided with the names of some mentors. Write a program that logs a shouty greeting to each one.
- In `exercise.js` write a program that displays the percentage of students and mentors in the group
- The percentage should be rounded to the nearest whole number (use a search engine to find out how to do this with JavaScript)
- You should have one function that calculates the percentage, and one function that creates a message

> Consider: should your percentage function do the rounding, or should it be done when the greeting is created?

## Expected result

```
Percentage students: 65%
Percentage mentors: 35%
```

## Exercise 2

- In `exercise2.js` you have been provided with the names of some mentors. Write a program that logs a shouty greeting to each one.
- Your program should include a function that spells their name in uppercase, and a function that creates a shouty greeting.
- Log each greeting to the console.

Expand Down
5 changes: 0 additions & 5 deletions exercises/L-functions-nested/exercise.js

This file was deleted.

18 changes: 18 additions & 0 deletions exercises/L-functions-nested/exercise1A.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// Option A [I had help to do this task, because I couldn't work it out by myself]

// First, created a function that calculated the percentage and round it
function getPercentage(subset, total) {
let percentage = Math.round((subset * 100) / total);
return percentage;
}
// After that, created another function that generated sentences using the percentage's function above
function getMessage(numberOfStudents, numberOfMentors) {
let total = numberOfStudents + numberOfMentors;
let studentPercentage = getPercentage(numberOfStudents, total);
let mentorPercentage = getPercentage(numberOfMentors, total);
let studentMessage = "Percentage of students: " + studentPercentage + "%";
let mentorMessage = "Percentage of mentors: " + mentorPercentage + "%";
return studentMessage + "\n" + mentorMessage;
}
// Called the last function to generate the sentences expected
console.log(getMessage(16, 30));
19 changes: 19 additions & 0 deletions exercises/L-functions-nested/exercise1B.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
// Option B [I had help to do this task, because I couldn't work it out by myself]

// Created two separate functions
function getPercentage(subset, total) {
let percentage = Math.round((subset * 100) / total);
return percentage;
}
function getMessage(group, percentage) {
let message = "Percentage of " + group + ": " + percentage + "%";
return message;
}
// Created variables to store values from the functions and call them for the students
let studentsPercentage = getPercentage(16, 46);
let studentsMessage = getMessage("students", studentsPercentage);
console.log(studentsMessage);
// Created variables to store values from the functions and call them for the mentors
let mentorsPercentage = getPercentage(30, 46);
let mentorsMessage = getMessage("mentors", mentorsPercentage);
console.log(mentorsMessage);
18 changes: 18 additions & 0 deletions exercises/L-functions-nested/exercise1C.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// Option C

// Created a function with several variables that when called would return the expected output
function doPercentage(mentors, students) {
let allStudents = students;
let allMentors = mentors;
let allAdults = allStudents + allMentors;
let percentageStudents = (allStudents * 100) / allAdults;
let percentageMentors = (allMentors * 100) / allAdults;
let allPercentagesS =
"Percentage of students: " + Math.round(percentageStudents) + "%.";
let allPercentagesM =
"Percentage of mentors: " + Math.round(percentageMentors) + "%.";
let allPercentages = allPercentagesS + allPercentagesM;
return allPercentages;
}

console.log(doPercentage(16, 30));
17 changes: 17 additions & 0 deletions exercises/L-functions-nested/exercise2.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// I got rid of the original list of variables and made it into an array below

// Created a nested function, the first one turns letters upper case and the second one displays the greeting to the mentors
function capitalisedString(message) {
let capitalisedShoutOut = message.toUpperCase();
return capitalisedShoutOut;
}
function shoutOut(theMentors) {
for (i = 0; i < theMentors.length; i++) {
let shoutOut = "Hello " + theMentors[i];
let capitalisedShoutOut = capitalisedString(shoutOut);
console.log(capitalisedShoutOut);
}
}
let theMentors = ["Daniel", "Irina", "Mimi", "Rob", "Yohannes"];
shoutOut(theMentors);
// Once you specify the array of names, you can use the function (line 22)
19 changes: 17 additions & 2 deletions extra/1-currency-conversion.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,15 @@
Write a function that converts a price to USD (exchange rate is 1.4 $ to £)
*/

function convertToUSD() {}
// This function multiplies the value of a GBP to convert it into USD. You could also put it all in one line but I see it clearer this way
function convertToUSD(priceGBP) {
let priceUSD = priceGBP * 1.4;
return priceUSD;
// return "$" + priceUSD.toFixed(2);
// This could be added if you wanted to put the currency symbol and some decimals
}

console.log(convertToUSD(32));

/*
CURRENCY FORMATTING
Expand All @@ -15,7 +23,14 @@ 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() {}
// Following the same principle as for the previous function, but taking into consideration the transaction fee, which needs to be worked out too
function convertToBRL(priceGBP) {
let foreignFee = (priceGBP * 1) / 100;
let priceBRL = (priceGBP - foreignFee) * 5.7;
return priceBRL;
}

console.log(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
Loading