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
3 changes: 3 additions & 0 deletions 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(1);
console.log("Hello World. I just started learning JavaScript!");
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`
let greeting = "Hello everyone, I am learning JavaScript";

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

var message = "This is a string";
var messageType = typeof message;

console.log(message);
console.log(messageType);
7 changes: 6 additions & 1 deletion exercises/E-strings-concatenation/exercise.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
// Start by creating a variable `message`

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

var greeting = greetingStart + firstName;

console.log(greeting);
9 changes: 9 additions & 0 deletions exercises/F-strings-methods/exercise.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
// Start by creating a variable `message`
var name = "Mustafa";
var nameLength = name.length;
var message =
"Hello, my name is " +
name +
" and my name is " +
nameLength +
" characters long.";

console.log(nameLength);
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 ";
const firstName = " Daniel ";
let message = "Hello, my name is " + firstName.trim();

console.log(firstName);

console.log(firstName.trim());
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 result=numberOfMentors+numberOfStudents;
console.log("Number of mentors: "+ numberOfMentors )
console.log("Number of students: " + numberOfStudents)
console.log("Total number of students and mentors: "+ 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;

var result=numberOfMentors+numberOfStudents;

console.log("Total people in the class "+ result)

var percentageStudents=(numberOfStudents/result)*100;
var percentageMentors=(numberOfMentors/result)*100;

console.log("Percentage of mentors: " +percentageMentors)
console.log("Rounded percentage of mentors: " + Math.round(percentageMentors))
console.log("Percentage of students: " + percentageStudents)
console.log("Rounded percentage of students: " + Math.round(percentageStudents))
5 changes: 4 additions & 1 deletion exercises/J-functions/exercise.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
function halve(number) {
// complete the function here
return number/2;
}

var result = halve(12);


console.log(result);
var result = halve(256);
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);

var result = triple(11);
console.log(result);
4 changes: 2 additions & 2 deletions exercises/K-functions-parameters/exercise.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// 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`
Expand Down
4 changes: 3 additions & 1 deletion exercises/K-functions-parameters/exercise2.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
// Declare your function first
function divide(num1, num2) {
return num1 / num2;
}

var result = divide(3, 4);

Expand Down
5 changes: 3 additions & 2 deletions exercises/K-functions-parameters/exercise3.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
// Write your function here

function createGreeting(name) {
return "Hello my name is, " + name;
}
var greeting = createGreeting("Daniel");

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

// Call the function and assign to a variable `sum`

let sum=total(13, 124)
console.log(sum);
8 changes: 7 additions & 1 deletion exercises/K-functions-parameters/exercise5.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
// Declare your function here
function createLongGreeting(name, age){


return "Hello, my name is "+name+" and I'm "+age+" years old."

}// Declare your function here

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

console.log(greeting);

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

function greetForMentors(mentorName) {
return "HELLO " + mentorName.toUpperCase();
}

console.log(greetForMentors(mentor1));
console.log(greetForMentors(mentor2));
console.log(greetForMentors(mentor3));
console.log(greetForMentors(mentor4));
console.log(greetForMentors(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";
}

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

return "The total is total";
return "The total is "+ total;
Comment on lines +3 to +14

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Excellent work :)

}

/*
Expand Down
8 changes: 3 additions & 5 deletions mandatory/2-logic-error.js
Original file line number Diff line number Diff line change
@@ -1,18 +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;
}
Comment on lines +4 to 13

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Excellent work :)


/*
===================================================
======= TESTS - DO NOT MODIFY BELOW THIS LINE =====
Expand Down
2 changes: 2 additions & 0 deletions mandatory/3-function-output.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ function combine2Words(word1, 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.

Could you add comments to explain the two functions above please?


function concatenate(firstWord, secondWord, thirdWord) {

return firstWord.concat(" ", 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.

Good job

// 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
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(productPrice) {
let productTax = (productPrice*20) / 100 + productPrice;

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Don't forget to indent. If you set up prettier and 'format on save' correctly, then this should happen automatically: https://github.com/CodeYourFuture/JavaScript-Core-1-Coursework-Week1/tree/master/exercises/A-setup-ide

Let me know if you need any help with that

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'm not sure if you were introduced to let vs const yet. This is a variable that doesn't need to change, so you'd be better off using const. See here: https://medium.com/javascript-scene/javascript-es6-var-let-or-const-ba58b8dcde75#:~:text=%60const%60%20is%20a%20signal%20that,always%20the%20entire%20containing%20function.

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 is more of an advanced comment, but it's usually bad to have 'magic numbers' in code i.e. any numbers that don't have an obvious meaning. So I'd advise using an extra line to explain that the 20 is the tax rate (the 100 is okay because it's obvious in the code that you're using it to make a percentage):

function calculateSalesTax(originalPrice) {
  const taxRate = 20;
  const taxOnOriginal = originalPrice * (taxRate / 100);
  return originalPrice + taxOnOriginal;
}

return productTax;}

/*
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(productPrice) {
return "£" + calculateSalesTax(productPrice).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.

Nice :)

}

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 Mustafa I checked your code nice job all of tests has passsed. I like to use this method for getting decimal points that we need.


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