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

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

console.log("JavaScript is challenging but it is fun");

console.log("You need to practices regularly");

// This will throw an error
// console.log(Hozan Ali)

console.log(2021);

console.log(2022);
3 changes: 3 additions & 0 deletions exercises/C-variables/exercise.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
// Start by creating a variable `greeting`
var greeting = "Hello world";

console.log(greeting);
console.log(greeting);
console.log(greeting);
2 changes: 2 additions & 0 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`
var message = "This is a string";

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 greetingMessage = "Hello, my name is ";
var myName = "Hozan";
var message = greetingMessage + myName;

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`
var myName = "Hozan";
var nameLength = myName.length;
var message = "My name is " + myName + " and my name is " + nameLength + " characters long";
Comment on lines +2 to +4
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

This looks great Hozan! As a challenge, you can make use of template literals. 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.

Thanks for the feedback Omar, the documents you provided looks great, I already went through them and found some useful info, I want to also note that in some exercises I did apply template literals, while in others I left them to have string literlas just so I practice how to use them both. Many Thanks


console.log(message);
1 change: 1 addition & 0 deletions exercises/F-strings-methods/exercise2.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
const name = " Daniel ";
var message = "My name is " + name.trim() + " and my name is " + name.trim().length + " characters long";

console.log(message);
7 changes: 7 additions & 0 deletions exercises/G-numbers/exercise.js
Original file line number Diff line number Diff line change
@@ -1 +1,8 @@
// Start by creating a variables `numberOfStudents` and `numberOfMentors`
let numberOfStudents = 15;
let numberOfMentors = 8;
let sumOfParticipants = numberOfStudents + numberOfMentors;

console.log("Number of students: " + numberOfStudents);
console.log("Number of mentors: " + numberOfMentors);
console.log("Total number of students and mentors: " + sumOfParticipants);
7 changes: 7 additions & 0 deletions exercises/I-floats/exercise.js
Original file line number Diff line number Diff line change
@@ -1,2 +1,9 @@
var numberOfStudents = 15;
var numberOfMentors = 8;
var total = numberOfStudents + numberOfMentors;

var percentageOfStudents = Math.round((numberOfStudents / total) * 100) + "%";
var percentageOfMentors = Math.round((numberOfMentors / total) * 100) + "%";

console.log("Percentage of students: " + percentageOfStudents);
console.log("Percentage of mentors: " + percentageOfMentors);
7 changes: 6 additions & 1 deletion exercises/J-functions/exercise.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
function halve(number) {
// complete the function here
return number / 2;
}

var result = halve(12);
console.log(result);

result = halve(20);
console.log(result);

result = halve(22);
console.log(result);
4 changes: 3 additions & 1 deletion 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);

result = triple (15);
console.log(result);
5 changes: 2 additions & 3 deletions exercises/K-functions-parameters/exercise.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
// Complete the function so that it takes input parameters
function multiply() {
// Calculate the result of the function and return it
function multiply(num1, num2) {
return num1 * num2;
}

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

console.log(result);
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(num1, num2){
return num1 / num2;
}

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(myName){
return "Hello, my name is " + myName;
}

var greeting = createGreeting("Daniel");

Expand Down
5 changes: 4 additions & 1 deletion 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 addNum(num1, num2){
return num1 + num2;
}
// Call the function and assign to a variable `sum`
var sum = addNum(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(myName, age){
return `Hello, my name is ${myName} and I'm ${age} years old`;
}

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

Expand Down
17 changes: 12 additions & 5 deletions exercises/L-functions-nested/exercise.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
var mentor1 = "Daniel";
var mentor2 = "Irina";
var mentor3 = "Mimi";
var mentor4 = "Rob";
var mentor5 = "Yohannes";
function percentage(number, total){
return Math.round((number / total) * 100);
};


function getResults(type, number, total){
var getPercentage = percentage(number, total);
return `Percentage ${type}: ${getPercentage}%`;
};

console.log(getResults("students",15,23));
console.log(getResults("mentors",8,23));
20 changes: 20 additions & 0 deletions exercises/L-functions-nested/exercise2.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
var mentor1 = "Daniel";
var mentor2 = "Irina";
var mentor3 = "Mimi";
var mentor4 = "Rob";
var mentor5 = "Yohannes";

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

function shoutyGreeting(greeting, name){
var getCapitalName = capitalName(name);
return `${greeting.toUpperCase()} ${getCapitalName}`;
};

console.log(shoutyGreeting("hello",mentor1));
console.log(shoutyGreeting("hello",mentor2));
console.log(shoutyGreeting("hello",mentor3));
console.log(shoutyGreeting("hello",mentor4));
console.log(shoutyGreeting("hello",mentor5));
15 changes: 8 additions & 7 deletions mandatory/1-syntax-errors.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
// 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;
var total = a + b;

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

/*
===================================================
Expand Down
7 changes: 3 additions & 4 deletions mandatory/2-logic-error.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
// 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 getWordLength(word) {
return "word".length();
return word.length;
}

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

/*
Expand Down
5 changes: 4 additions & 1 deletion mandatory/3-function-output.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,19 @@
// Add comments to explain what this function does. You're meant to use Google!
function getNumber() {
return Math.random() * 10;
return Math.random() * 10;
}
// The function above will return a random floating point between 0 and 10 (not included), The random() method returns a random floating number from 0 (inclusive) up to but not including 1 (exclusive)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Hi Hozan, when if you run Math.random what output do you get? If you multiple the result of Math.random with 10 does it result in an integer?

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.

Hi @louisechow , many thanks for the feedback.
You are right, I should have worded my answer properly.
The Math.random method will return a floating point number between 0 and 1 (not included), and when it is multiplied by 10 we will still get a floating point number between 0 and 10 (not included).

// Add comments to explain what this function does. You're meant to use Google!
function s(w1, w2) {
return w1.concat(w2);
}
// The concat() method above is used to join or concatenate the two parameters W1 and W2, so the function will return a new string of w1 + w2.

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.
return `${firstWord} ${secondWord} ${thirdWord}`;
}

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

function calculateSalesTax() {}
function calculateSalesTax(priceBeforeTax) {
return priceBeforeTax + (priceBeforeTax * 0.2)
}

/*
CURRENCY FORMATTING
Expand All @@ -17,7 +19,9 @@ function calculateSalesTax() {}
Remember that the prices must include the sales tax (hint: you already wrote a function for this!)
*/

function addTaxAndFormatCurrency() {}
function addTaxAndFormatCurrency(priceBeforeTax) {
return `£${calculateSalesTax(priceBeforeTax).toFixed(2)}`
}

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