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
Binary file added .DS_Store
Binary file not shown.
Binary file added exercises/.DS_Store
Binary file not shown.
2 changes: 1 addition & 1 deletion exercises/B-hello-world/exercise.js
Original file line number Diff line number Diff line change
@@ -1 +1 @@
console.log("Hello world");
console.log("Hayaaa");
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`

let greeting= "hello";
console.log(greeting);
console.log(greeting);
console.log(greeting);


4 changes: 2 additions & 2 deletions exercises/D-strings/exercise.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
// Start by creating a variable `message`

console.log(message);
let message = "";
console.log(typeof message);
5 changes: 4 additions & 1 deletion 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`
let greeting = "Hello, my name is ";
let firstName ="Maira";
let fullGreeting = greeting + firstName;
console.log(fullGreeting);

console.log(message);
3 changes: 3 additions & 0 deletions exercises/F-strings-methods/exercise.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
// Start by creating a variable `message`
let firstName = "Maira";
let nameLength = firstName.length

let message = "My name is " + firstName + " and my name is 5 characters long"
console.log(message);
6 changes: 5 additions & 1 deletion exercises/F-strings-methods/exercise2.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
const name = " Daniel ";

console.log(message);
let message = "My name is " + firstName + " and my name is 5 characters long";

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

  1. Variable firstName doesn't exist here. You need to use name instead.
  2. Use a string method to calculate the length of your name rather than writing it directly here as 5.
  3. You need to use .trim() on the name to clear extra spacing around it.
  4. It's almost always better to use this format for string concatinations:
    Like this:
name = name.trim()
let message =`My name is ${name} and my name is ${name.length} characters long`

let result = message.trim();
console.log(result);
// let text = " Hello World! ";
// let result = text.trim();
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 = 50;
let numberOfMentors = 20;
let result = numberOfStudents + numberOfMentors;

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Use const when your variable value won't change at all.
Use let when the content of your variable will change later in the code.

Therefore, here you can change all the let to const.

console.log(result);
12 changes: 12 additions & 0 deletions exercises/I-floats/exercise.js
Original file line number Diff line number Diff line change
@@ -1,2 +1,14 @@
var numberOfStudents = 15;
var numberOfMentors = 8;
let total = numberOfStudents + numberOfMentors;
let percentageOfStudents = numberOfStudents * 100/ total;
let newPercentageOfStudents= Math.round(percentageOfStudents);
console.log(newPercentageOfStudents);
let percentageOfMentors = numberOfMentors * 100/ total;
let newPercentageOfMentors = Math.round(percentageOfMentors);

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Again, you can use const in this file instead of all the lets.

console.log(newPercentageOfMentors);



// var preciseAge = 30.612437;
// var roughAge = Math.round(preciseAge);
9 changes: 9 additions & 0 deletions exercises/J-functions/exercise.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,16 @@
function halve(number) {
// complete the function here
return number/2;

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Correct spacing:

return number / 2;

}

var result = halve(12);

console.log(result);


// function double(number) {
// return number * 2;
// }
// var result = double(2);

// console.log(result); // 4
1 change: 1 addition & 0 deletions exercises/J-functions/exercise2.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
function triple(number) {
// complete function here
return number * 3;
}

var result = triple(12);
Expand Down
5 changes: 4 additions & 1 deletion exercises/K-functions-parameters/exercise.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@


// 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;

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Correct spacing:

return a * b;

}

// Assign the result of calling the function the variable `result`
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;

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Correct spacing:

return a / b;

}

var result = divide(3, 4);

Expand Down
17 changes: 16 additions & 1 deletion exercises/K-functions-parameters/exercise3.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,20 @@
// Write your function here

var greeting = createGreeting("Daniel");
function createGreeting (){
let name = "Daniel"
let message = "hello my name is " + name;

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Again, this format is better to use: Hello ... ${name}

return message

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Indent

}

var greeting = createGreeting("Maira");

console.log(greeting);

// let userName = 'John';

// function showMessage() {
// let message = 'Hello, ' + userName;
// alert(message);
// }

// showMessage(); // Hello, John
9 changes: 7 additions & 2 deletions exercises/K-functions-parameters/exercise4.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
// Declare your function first

// - 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`
// Call the function and assign to a variable `sum`

let num1 = 13;
let num2 = 124;
function addNum (num1, num2){
return num1+ num2;
}
console.log(sum);
11 changes: 8 additions & 3 deletions exercises/K-functions-parameters/exercise5.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
// Declare your function here

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

// Write a function that takes a name (a string) and an age (a number) and returns a greeting (a string)
// const greeting = createLongGreeting("Daniel", 30);
function createLongGreeting(name, age){

return `Hello, my name is ${name} and I'm ${age} years old`;

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 use of concat and interpolation overall, the best option

}
let greeting = createLongGreeting("Daniel", 30);
// let greeting = createLongGreeting("Maira", 32);
console.log(greeting);
13 changes: 13 additions & 0 deletions exercises/L-functions-nested/exercise.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,16 @@ var mentor2 = "Irina";
var mentor3 = "Mimi";
var mentor4 = "Rob";
var mentor5 = "Yohannes";

function toUpperCase(name){
return name.toUpperCase();
}
function sayHello(mentor){
let upperLetter = toUpperCase(mentor);
return `HELLO ${upperLetter}`;
}
console.log(sayHello(mentor1));
console.log(sayHello(mentor2));
console.log(sayHello(mentor3));
console.log(sayHello(mentor4));
console.log(sayHello(mentor5));
18 changes: 13 additions & 5 deletions mandatory/1-syntax-errors.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,24 @@
// 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;
total = a + b;

return "The total is total";
return "The total is " + total;
}

/*
Expand Down
8 changes: 4 additions & 4 deletions mandatory/2-logic-error.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
// 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();
}

function getStringLength(word) {
return "word".length();
return word.length;
}

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

return a * b * c ;
}

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

// This function getting random number between 0(inclusive) and 1 (inclusive) sourse https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/random
function getRandomNumber() {
return Math.random() * 10;
}

// Add comments to explain what this function does. You're meant to use Google!

// this function combining 2 words by using concat method sourse https://www.w3schools.com/jsref/tryit.asp?filename=tryjsref_concat_string1
function combine2Words(word1, word2) {
return word1.concat(word2);
}

function concatenate(firstWord, secondWord, thirdWord) {
return firstWord + " " + secondWord + " " + thirdWord;

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

There is another way of doing this if you follow the link above

// 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.
}
Expand Down
27 changes: 24 additions & 3 deletions mandatory/4-tax.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,17 @@
Sales tax is 20% of the price of the product.
*/

function calculateSalesTax() {}

function calculateSalesTax(price) {
let totalPrice = price * 0.2 + 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.

another way is return price * 1.2

return totalPrice;
}
let totalPrice = calculateSalesTax(15);
console.log(totalPrice);
let totalPrice2 = calculateSalesTax(17.50);
console.log(totalPrice2);
let totalPrice3 = calculateSalesTax(34);
console.log(totalPrice3);

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

We don't want to keep any debugging code in our tests. We should remove all the console.logs from our test files.
The tests furthur in the file will correctly evaluate the tests.


/*
CURRENCY FORMATTING
===================
Expand All @@ -16,8 +25,20 @@ function calculateSalesTax() {}

Remember that the prices must include the sales tax (hint: you already wrote a function for this!)
*/
// Компания сообщила вам, что цены должны иметь 2 десятичных знака.
// Они также должны начинаться с символа валюты.
// Напишите функцию, которая добавляет налог к числу, а затем преобразует итоговую сумму в формат 0,00 фунтов стерлингов.

function addTaxAndFormatCurrency() {}
// Помните, что цены должны включать налог с продаж (подсказка: вы уже написали для этого функцию!)
function addTaxAndFormatCurrency(number) {
// let addTax = number + totalPrice;
// return `£${addTax}`;
let result = `£${calculateSalesTax(number).toFixed(2) }`;
return result
}
console.log( addTaxAndFormatCurrency(15) )
console.log( addTaxAndFormatCurrency(17.50) )
console.log( addTaxAndFormatCurrency(34) )

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