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
5 changes: 4 additions & 1 deletion exercises/B-hello-world/exercise.js
Original file line number Diff line number Diff line change
@@ -1 +1,4 @@
console.log("Hello world");
console.log("Hello World. I just started learning JavaScript!.");
console.log("I like playing piano.");
console.log(2 + 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.

Great work!

4 changes: 4 additions & 0 deletions 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 world";

console.log(greeting);
console.log(greeting);
console.log(greeting);

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!

4 changes: 4 additions & 0 deletions exercises/D-strings/exercise.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
// Start by creating a variable `message`
let message = "This is a string";
let messageType = typeof message;

console.log(message);
console.log(messageType);

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!

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 greetingStart = " Hello my name is ";
let name = "Ntshumayelo";

console.log(message);
let greeting = greetingStart + name;
console.log(greeting);

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 work on providing a working solution.

For future reference: attention to detail is really important for a program.
Hello my name is Ntshumayelo
Is different from the expected
Hello, my name is Ntshumayelo
A comma after Hello and no space at the beginning of the greetingStart variable.

5 changes: 4 additions & 1 deletion 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 name = "Ntshumayelo";
let message = "My name is Ntshumayelo";

console.log(message);
console.log(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.

The variable nameLength was used but not defined !! Please define it first before using it.


6 changes: 4 additions & 2 deletions exercises/F-strings-methods/exercise2.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
const name = " Daniel ";

const name = "Daniel";

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

The .trim method can only be useful when the name has empty space before and/or after so something like this was expected const name = ' Daniel '. So please update accordingly

let lengthName = name.length
let message = "my name is " + name.trim() + " and my name is " + lengthName + " characters long";
console.log(message);
//console.log(name.trim);
12 changes: 12 additions & 0 deletions exercises/G-numbers/exercise.js
Original file line number Diff line number Diff line change
@@ -1 +1,13 @@
// Start by creating a variables `numberOfStudents` and `numberOfMentors`
let numberOfStudents = 15
let numberOfMentors = 8
let totalNumberOfStudentsMentors = numberOfStudents + numberOfMentors;

let percentageOfStudents = numberOfStudents * 100 /totalNumberOfStudentsMentors;
percentageOfStudents = Math.round(percentageOfStudents);
console.log("Percentage of Students: " + percentageOfStudents + "%");


let percentageOfMentors = numberOfMentors * 100 /totalNumberOfStudentsMentors;
percentageOfMentors = Math.round(percentageOfMentors);
console.log("Percentage of Mentors: " + 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.

A great working solution and use of the Math function; Despite the ask of this exercise, i'm considering this as well done since the solution provided is more complex than the expected ask below.

For future reference, please stick to the ask.

The expected result was something like this:

Number of students: 15
Number of mentors: 8
Total number of students and mentors: 23

4 changes: 3 additions & 1 deletion exercises/J-functions/exercise.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
function halve(number) {
let result = number / 2;
return result;
// complete the function here
}

var result = halve(12);
let result = halve(12);

console.log(result);

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Well done!

  let result = number / 2;
  return result;
}

can be written like this, because when are returning a value after a calculation we dont need to give it a name, and we can just return it like below:

function halve(number) {
  return (number / 2);
}

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

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.


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,5 +1,7 @@
// Complete the function so that it takes input parameters
function multiply() {
function multiply(num1, num2) {
let result = num1 * num2;
return result;

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.

FYI: see the above comment regarding the use of return in this type of small function

// Calculate the result of the function and return it
}

Expand Down
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(num1, num2){
let result = num1 / num2;
return result;
}
var result = divide(3, 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.

Great.

FYI:
--> See the above comment for the use of return
--> Please check the indentation of the code, it's a good practice to have a consistent indentation within the codebase


console.log(result);
7 changes: 5 additions & 2 deletions exercises/K-functions-parameters/exercise3.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
// Write your function here

var greeting = createGreeting("Daniel");
function createGreeting(name){
let greeting = "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.

To display a variable within a string you need to use the backtick ``

let greeting = `Hello, My name is ${name}`

return greeting;
}
let greeting = createGreeting("Daniel");

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

let sum = sumNumbers(13,124)
console.log(sum);

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Well done.

5 changes: 4 additions & 1 deletion exercises/K-functions-parameters/exercise5.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
// Declare your function here

function createLongGreeting(name, age){
let greeting = "Hello, my name is ${name} and I'm ${age} 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.

See above the comment on using backtick when trying to insert a variable into a string

let greeting = `Hello, my name is ${name} and I'm ${age} old`

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

console.log(greeting);
2 changes: 1 addition & 1 deletion exercises/L-functions-nested/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ function createCreeting(name, age) {
```
HELLO DANIEL
HELLO IRINA
HELLO MIMI
HELLO MIMIv
HELLO ROB
HELLO YOHANNES
```
19 changes: 19 additions & 0 deletions exercises/L-functions-nested/exercise.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,22 @@ var mentor2 = "Irina";
var mentor3 = "Mimi";
var mentor4 = "Rob";
var mentor5 = "Yohannes";

let mentor1 = "Daniel";
let mentor2 = "Irina";
let mentor3 = "Mimi";
let mentor4 = "Rob";
let mentor5 = "Yohannes";

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

While the use of let is recommended, we can't have the same value declared as above with both let and var.
Either delete all the mentors' names declarations using var and keep the ones using let, or delete the let and keep the var.
It should be fine after that


function spellName(name) {
return name.toUpperCase();
}
function shoutyGreeting(name){
let message = 'HELLO '+ spellName(name);
return message
};
console.log(shoutyGreeting(mentor1));
console.log(shoutyGreeting(mentor2));
console.log(shoutyGreeting(mentor3));
console.log(shoutyGreeting(mentor4));
console.log(shoutyGreeting(mentor5));
11 changes: 6 additions & 5 deletions mandatory/1-syntax-errors.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
// 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";

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Attention to detail is key with every program. The test will fail because there needs to be space as below:

return "Hello, my name is " + name + " and I am " + age + " years old";

The rest of the code is perfect.

}

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;

}

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Well done.


/*
Expand Down
2 changes: 2 additions & 0 deletions mandatory/3-function-output.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
// Add comments to explain what this function does. You're meant to use Google!
//returns a random number between 0 (inclusive) and 1 (exclusive) and multiplies with 10
function getRandomNumber() {
return Math.random() * 10;
}

// Add comments to explain what this function does. You're meant to use Google!
// This function combines typed array with the new array.
function combine2Words(word1, word2) {
return word1.concat(word2);
}

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 a third function for this exercise.
Hint:

return firstWord.concat(' ').concat(secondWord).concat(' ').concat(thirdWord)

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

function calculateSalesTax() {}
function calculateSalesTax(priceOfProduct) {
let percentageOfProduct = (priceOfProduct) * 0.2;
return percentageOfProduct + (priceOfProduct);
}

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

function addTaxAndFormatCurrency() {}
function addTaxAndFormatCurrency(num) {
let priceWithSalesTax = calculateSalesTax(num);
return "£" + priceWithSalesTax.toFixed(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.

Well done.

===================================================
Expand Down