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
10 changes: 9 additions & 1 deletion exercises/B-hello-world/exercise.js
Original file line number Diff line number Diff line change
@@ -1 +1,9 @@
console.log("Hello world");

console.log("hello world");
console.log("I just started learning JavaScript!");
console.log("hi");





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 = "Hey! I am a variable";
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`

console.log(message);
let message = "this is text inside ' ' and the name is string"
console.log(typeof message);

9 changes: 9 additions & 0 deletions 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`

let students = "we are seven students";

let teacher = " and 2 teachers";

let message = students + teacher + " working in the proyect.";




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);
let message = " tell me how many words I am; ";
let stringLength = message.length;
console.log(message + "the length is: " + stringLength);
7 changes: 5 additions & 2 deletions exercises/F-strings-methods/exercise2.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
const name = " Daniel ";
const myname = "Karla";

console.log(message);
let CharactersLength = myname.length;


console.log(`my name is ${CharactersLength} characters`); //to make the interpolation is alwais the backticks
3 changes: 2 additions & 1 deletion exercises/G-numbers/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,14 @@ You can use mathematical operators to caclulate numbers:

```js
var sum = 10 + 2; // 12
var product = 10 * 2; // 20
var product = 10 * 2; // 20
var quotient = 10 / 2; // 5
var difference = 10 - 2; // 8
```

## Exercise


- Create two variables `numberOfStudents` and `numberOfMentors`
- Log a message that displays the total number of students and mentors

Expand Down
10 changes: 9 additions & 1 deletion exercises/G-numbers/exercise.js
Original file line number Diff line number Diff line change
@@ -1 +1,9 @@
// Start by creating a variables `numberOfStudents` and `numberOfMentors`
// Start by creating a variables
// `numberOfStudents` and `numberOfMentors`

let numberOfStudents = 15;
let numberOfMentors = 8;

let total = numberOfStudents + numberOfMentors;

console.log(`total number of studentes and mentor: ${total}`);
4 changes: 2 additions & 2 deletions exercises/I-floats/README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
Numbers can be integers (whole numbers) or floats (numbers with a decimal).

```js
var preciseAge = 30.612437;
```
var preciseAge = 30.612437; //float number
```

Floats can be rounded to the nearest whole number using the `Math.round` function:

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

let total = numberOfStudents + numberOfMentors;

console.log(`total number of studentes and mentor: ${total}`);

let porcentage = (numberOfStudents/total ) * 100; //here we did the average and the number return float
let porcentageB = (numberOfMentors/total ) * 100;

console.log(`Porcentage students ${Math.round(porcentage)}%`);// here we use the comand Math.round to make it again integer and we added %

console.log(`Porcentage Mentors ${Math.round(porcentageB)}%`);
4 changes: 3 additions & 1 deletion exercises/K-functions-parameters/exercise.js
Original file line number Diff line number Diff line change
@@ -1,8 +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);

Expand Down
3 changes: 3 additions & 0 deletions exercises/K-functions-parameters/exercise2.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
// Declare your function first
function divide(a, b){
return a/b;
}

var result = divide(3, 4);

Expand Down
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(a){
return "hell, my name is " + a;
}

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 totalSum(a, b){
return a + b;

}
// Call the function and assign to a variable `sum`
let sum = totalSum(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(a, b){
return `hello, my name is ${a} and I'm ${b} year old`;
}

const greeting = createLongGreeting("Daniel", 30);

Expand Down
15 changes: 15 additions & 0 deletions exercises/L-functions-nested/exercise.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,18 @@ var mentor2 = "Irina";
var mentor3 = "Mimi";
var mentor4 = "Rob";
var mentor5 = "Yohannes";


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

function createGreeting(name) {
return `HELLO ${convertNameToUpperCase(name)}`;
}

console.log(createGreeting(mentor1));
console.log(createGreeting(mentor2));
console.log(createGreeting(mentor3));
console.log(createGreeting(mentor4));
console.log(createGreeting(mentor5));
16 changes: 10 additions & 6 deletions mandatory/1-syntax-errors.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,22 @@
// 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 total";
function getTotal(a, b){
let total = a + b;
return `The total is ${total}`; //this line we combin

}


/*
===================================================
======= TESTS - DO NOT MODIFY BELOW THIS LINE =====
Expand Down
22 changes: 16 additions & 6 deletions mandatory/2-logic-error.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,26 @@
// The syntax for this function is valid but it has an error, find it and fix it.

function trimWord(word) {
return wordtrim();
//in this exercise we use the mothod .trim() which help to eliminate leading and trailing spaces.

function trimWord(phrase) {
let string = phrase.trim();
return string;
}

function getStringLength(word) {
return "word".length();
// the function .length will show the number of the string that we give by the parameter a
// we created a local variable where we store the result of the parameter

function getStringLength(a) {
let total = a.length;
return total;
}


//we declared a variable total to store the math operation then we sent the result in the return;

function multiply(a, b, c) {
a * b * c;
return;
let total = a * b * c;
return total;
}

/*
Expand Down
14 changes: 11 additions & 3 deletions mandatory/3-function-output.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,24 @@
// Add comments to explain what this function does. You're meant to use Google!


// this function generate a ramdom number between 0 to one number less than the maximun
// which we sent in the parametre. so we wil get from 0 to 9
function getRandomNumber() {
return Math.random() * 10;
return Math.random( ) * 10;
}
// console.log(getRandomNumber(10))

// Add comments to explain what this function does. You're meant to use Google!
//This function will combine two parametres in the same line
function combine2Words(word1, word2) {
return word1.concat(word2);
}

function concatenate(firstWord, secondWord, thirdWord) {
// Write the body of this function to concatenate three words together.
// Look at the test case below to understand what this function is expected to return.
// Write the body of this function to concatenate three words together.
// Look at the test case below to understand what this function is expected to return.
return firstWord.concat(" " + secondWord + " ").concat(thirdWord);
//we create the spaces that required with the " " and .concat help to join the parametres
}

/*
Expand Down
19 changes: 15 additions & 4 deletions mandatory/4-tax.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,15 @@
Sales tax is 20% of the price of the product.
*/

function calculateSalesTax() {}
function calculateSalesTax(price) {
let porcentage = price * 0.20; //we multiply with 0.20 to obtain the porcentage which
//will be included in the final price.
porcentage += price;
return porcentage;
}

/*

/*
CURRENCY FORMATTING
===================
The business has informed you that prices must have 2 decimal places
Expand All @@ -16,9 +22,14 @@ function calculateSalesTax() {}

Remember that the prices must include the sales tax (hint: you already wrote a function for this!)
*/
// let calculateSalestax = calculateSalestax;

function addTaxAndFormatCurrency() {}

function addTaxAndFormatCurrency(price) {
let finalPrice = `£${calculateSalesTax(price).toFixed(2)}`;
//we create a new variable and call the previus function and concatenate with £ and
// .toFixed will give us 2 digits to appear after the decimal point.
return finalPrice;
}
/*
===================================================
======= TESTS - DO NOT MODIFY BELOW THIS LINE =====
Expand Down
12 changes: 9 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,21 @@
"url": "https://github.com/CodeYourFuture/JavaScript-Core-1-Coursework-Week1/issues"
},
"jest": {
"setupFilesAfterEnv": ["jest-extended"],
"setupFilesAfterEnv": [
"jest-extended"
],
"projects": [
{
"displayName": "mandatory",
"testMatch": ["<rootDir>/mandatory/*.js"]
"testMatch": [
"<rootDir>/mandatory/*.js"
]
},
{
"displayName": "extra",
"testMatch": ["<rootDir>/extra/*.js"]
"testMatch": [
"<rootDir>/extra/*.js"
]
}
]
},
Expand Down