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 @@
console.log("Hello world");
console.log("Hello world");
// console.log(Hello);

var greeting = "Hello, I'm learning JavaScript";
greeting = "Hello world";
console.log(greeting);
2 changes: 1 addition & 1 deletion exercises/C-variables/README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
When you write code, you'll want to create shortcuts to data values so you can don't have to write out the same value every time.
When you write code, you'll want to create shortcuts to data values so you don't have to write out the same value every time.

We can use _variable_ to create a reference to a value.

Expand Down
5 changes: 5 additions & 0 deletions 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`
var greeting;
greeting = "Hello World";
console.log(greeting);
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));
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`

var greetingStart = "Hello, my name is ";
var name = "Dawit";
var message = greetingStart + name;
console.log(message);

7 changes: 6 additions & 1 deletion exercises/F-strings-methods/exercise.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
// Start by creating a variable `message`

var name = "Dawit";
var messageStart = "My name is";
var messageMiddle = "and my name is";
var messageEnd = "charactors long";
var nameLength = name.nameLength;

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 am not clear what do yo mean by nameLength = name.nameLength? where did you already declared nameLength

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.

I appreciate the comments. I'll make it right.

var message = messageStart + " " + name + " " + messageMiddle + " " + name.length + " " + messageEnd;
console.log(message);
8 changes: 6 additions & 2 deletions exercises/F-strings-methods/exercise2.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
const name = " Daniel ";

var name = " Dawit ";
var messageStart = "My name is";
var messageMiddle = "and my name is";
var messageEnd = "characters long";
var nameLength = name.nameLength;
var message = messageStart + " " + name.trim() + " " + messageMiddle + " " + name.length + " " + messageEnd;
console.log(message);
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 = 15;
var student = "Number of students: ";
var numberOfMentors = 8;
var mentors = "Number of mentors: ";

var total = numberOfStudents + numberOfMentors;
var totalOfAll = "Total number of students and mentors: ";

console.log(student + numberOfStudents);
console.log(mentors + numberOfMentors);
console.log(totalOfAll + total);
6 changes: 6 additions & 0 deletions exercises/I-floats/exercise.js
Original file line number Diff line number Diff line change
@@ -1,2 +1,8 @@
var numberOfStudents = 15;
var numberOfMentors = 8;

let total = numberOfStudents + numberOfMentors
let studentsPercentage = numberOfStudents / total * 100
console.log(Math.round(studentsPercentage) + "%")
let mentorsPercentage = (numberOfMentors * 100) / total
console.log(Math.round(mentorsPercentage) + "%")
2 changes: 2 additions & 0 deletions exercises/J-functions/exercise.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
function halve(number) {
var number = 12;
// complete the function here
return number - (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.

nice way to define halve number - (number / 2) you can also just divide the
number by 2

}

var result = halve(12);
Expand Down
4 changes: 4 additions & 0 deletions 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
var number = 12;

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 don't need write step 3 (var number = 12;) as passed "number" as parameter in the function.

return number = (number * 3);

}

var result = triple(12);

console.log(result);

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(a, b) {
// Calculate the result of the function and return it
return result = a * b;
}

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

console.log(result);

5 changes: 4 additions & 1 deletion exercises/K-functions-parameters/exercise2.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
// Declare your function first
function divide(a, b) {
return result = a / b;
}

var result = divide(3, 4);
var result = divide(1.5, 2);

console.log(result);
5 changes: 4 additions & 1 deletion 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 greeting = `Hello, my name is ${name}`
}

var greeting = createGreeting("Daniel");
var greeting = createGreeting("Dawit");

console.log(greeting);
5 changes: 5 additions & 0 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
function passing(a, b) {
return sum = a + b;
}

// Call the function and assign to a variable `sum`
var sum = passing(13, 124)

console.log(sum);

4 changes: 4 additions & 0 deletions exercises/K-functions-parameters/exercise5.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
// Declare your function here
function createLongGreeting(name, age) {
return greeting = "Hello, my name is " + name + "and my age is " + age + "years old";
}

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

console.log(greeting);

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

function mentors(name) {
return `HELLO ${name.toUpperCase()}!`;
}
console.log(mentors(mentor1))
console.log(mentors(mentor2))
console.log(mentors(mentor3))
console.log(mentors(mentor4))
console.log(mentors(mentor5))
13 changes: 8 additions & 5 deletions mandatory/1-syntax-errors.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,19 @@
// 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";

}
console.log(introduceMe("Dawit", 50))

function getTotal(a, b) {
total = a ++ b;
let total = a + b;

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

/*
Expand Down
12 changes: 6 additions & 6 deletions mandatory/2-logic-error.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
// 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;
}
console.log(multiply(2, 5, 6));

/*
===================================================
Expand Down
10 changes: 9 additions & 1 deletion mandatory/3-function-output.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,24 @@
function getRandomNumber() {
return Math.random() * 10;
}

//*
// The random() method returns a random value that is greater than or equal to 0.0 and less than 1.0.

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 explanation!

//*
// Add comments to explain what this function does. You're meant to use Google!
function combine2Words(word1, word2) {
return word1.concat(word2);
}
//*
// This function will join the two words without space between them.

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Suggested change
// This function will join the two words without space between them.
// This function will join the two words with a space between them.

//*

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.concat(" ", secondWord).concat(" ", 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.

I like the way you've called .concat() on the result of .concat()! Are you able to explain why this works?

}

console.log(concatenate("Code", "Your","Future"));

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

function calculateSalesTax() {}
function calculateSalesTax(price) {
let salesTax = (price * 20) / 100;

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 confused me to begin with as to why you were multiplying the price by 20. One of the reasons is that I have no idea what the significance of that number is. In the industry we'd refer to this as a "magic number". It's considered better to treat it as a named constant defined somewhere in your code. Some people/organisations will capitalize shared constants, something like:

const TAX_RATE = 20;

function calculateSalesTax(price) {
    let tax = price * TAX_RATE / 100;
    return price + tax;
}

let totalPrice = price + salesTax;
return totalPrice;
}

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

function addTaxAndFormatCurrency() {}

function addTaxAndFormatCurrency(amount) {
// const total = calculateSalesTax(amount);
// const formattedTotal = `£${total.toFixed(2)}`;
// return formattedTotal;
return `£${calculateSalesTax(amount).toFixed(2)}`;
}
console.log(addTaxAndFormatCurrency(17.5));
/*
===================================================
======= TESTS - DO NOT MODIFY BELOW THIS LINE =====
Expand Down