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
Binary file added .DS_Store
Binary file not shown.
Binary file added exercises/.DS_Store
Binary file not shown.
6 changes: 5 additions & 1 deletion exercises/B-hello-world/exercise.js
Original file line number Diff line number Diff line change
@@ -1 +1,5 @@
console.log("Hello world");
console.log("Hello world. This is a Test");
console.log("Hjkl;fe c");
console.log("Hellodsxzwsaz`is a Test");
console.log("Hello world. Tlllllllllllllllllll");
console.log(8);
4 changes: 3 additions & 1 deletion exercises/C-variables/exercise.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// Start by creating a variable `greeting`

let greeting = "Hello World!";
console.log(greeting);
console.log(greeting);
console.log(greeting);
4 changes: 3 additions & 1 deletion 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`

let message = "This is my message";
let messageType = typeof message;
console.log(message);
console.log(messageType);
4 changes: 3 additions & 1 deletion exercises/E-strings-concatenation/exercise.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// Start by creating a variable `message`

let greeting = "My name is ";
let myName = "Meysam Arshadi";
let message = greeting + myName;
console.log(message);
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 = "Daniel";
let nameLength = name.length;
let message =
"My name is " + name + " and it is " + nameLength + " charachter.";
console.log(message);
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";
let nameLength = name.length;
let message =
"My name is " + name + " and it is " + nameLength + " charachter.";
console.log(message);
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 studentMessage = "Total No of students: " + numberOfStudents;
console.log(studentMessage);

let numberOfMentors = 5;
let mentorsMessage = "Total No of mentors: " + numberOfMentors;
console.log(mentorsMessage);

let total = numberOfStudents + numberOfMentors;
let message = "Total number of students and mentors: " + total;

console.log(message);
10 changes: 8 additions & 2 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 numberOfStudents = 15;
let numberOfMentors = 8;
let total = numberOfStudents + numberOfMentors;
console.log("Total:" + " " + total);
let studentPercentage = (numberOfStudents * 100) / total;
console.log("Student percentage:" + " %" + Math.round(studentPercentage));
let mentorPercentage = (numberOfMentors * 100) / total;
console.log("Mentor percentage:" + " %" + Math.round(mentorPercentage));
4 changes: 2 additions & 2 deletions exercises/J-functions/exercise.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
function halve(number) {
// complete the function here
return (number = number / 2);
}

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

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

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

you don't need to overwrite the variable. You can just go : return (variable * 3)

}

var result = triple(12);
Expand Down
15 changes: 8 additions & 7 deletions exercises/K-functions-parameters/exercise.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
// Complete the function so that it takes input parameters
function multiply() {
// Calculate the result of the function and return it
function logGreeting(name) {
let captalizedName = name.toUpperCase();
return "HELLO " + captalizedName;
}

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

console.log(result);
console.log(logGreeting("Daniel"));
console.log(logGreeting("Irina"));
console.log(logGreeting("Mimi"));
console.log(logGreeting("Rob"));
console.log(logGreeting("Yohannes"));
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 (divide = 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.

same here

}

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(name) {
return "My name is" + " " + name;
}

var greeting = createGreeting("Daniel");

Expand Down
6 changes: 4 additions & 2 deletions exercises/K-functions-parameters/exercise4.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
// Declare your function first

function addNumbers(a, b) {
return a + b;
}
// Call the function and assign to a variable `sum`

let sum = addNumbers(13, 124);
console.log(sum);
13 changes: 12 additions & 1 deletion exercises/K-functions-parameters/exercise5.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,16 @@
// Declare your function here

function createLongGreeting(name, age) {
return (
"Hello! My name is" +
" " +
name +
"and I am" +
" " +
age +
" " +
"year old."
);
}
const greeting = createLongGreeting("Daniel", 30);

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

function logGreeting(name) {
let upperCaseName = name.upperCaseName;
return "HELLO" + upperCaseName;
}

console.log(logGreeting);
20 changes: 13 additions & 7 deletions mandatory/1-syntax-errors.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,24 @@
// There are syntax errors in this code - can you fix it to pass the tests?

function addNumbers(a b c) {
return a + b + c;
function addNumbers(a, b, c) {
let total = a + b + c;
return total;
}

function introduceMe(name, age)
return "Hello, my name is " + name "and I am " age + "years old";
console.log(addNumbers(3, 4, 6));

function getTotal(a, b) {
total = a ++ b;
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.

just as side note, it is also possible to use interpolation if that is more practical
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Template_literals

}

return "The total is total";
console.log(introduceMe("Sonjide", 27));

function getTotal(a, b) {
total = a + b;
return "The total is " + total;
}

console.log(getTotal(23, 5));
/*
===================================================
======= TESTS - DO NOT MODIFY BELOW THIS LINE =====
Expand Down
14 changes: 10 additions & 4 deletions mandatory/2-logic-error.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,24 @@
// 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();
}

console.log(trimWord(" CodeYourFuture "));
console.log(trimWord(" CodeYourFuture teaches coding "));

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

console.log(getStringLength("Turtles"));
console.log(getStringLength("A wild sentence appeared!"));

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

console.log(multiply(2, 3, 6));
/*
===================================================
======= TESTS - DO NOT MODIFY BELOW THIS LINE =====
Expand Down
8 changes: 8 additions & 0 deletions mandatory/3-function-output.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,26 @@
// Add comments to explain what this function does. You're meant to use Google!
// My answer: The Math.random() function returns a floating-point, pseudo-random number that's greater than or equal to 0 and less than 1, with approximately uniform distribution over that range — which you can then scale to your desired range. The implementation selects the initial seed to the random number generation algorithm; it cannot be chosen or reset by the user.

function getRandomNumber() {
return Math.random() * 10;
}

// Add comments to explain what this function does. You're meant to use Google!
// My answer: In JavaScript, concat() is a string method that is used to concatenate strings together. The concat() method appends one or more string values to the calling string and then returns the concatenated result as a new string. Because the concat() method is a method of the String object, it must be invoked through a particular instance of the String class.

function combine2Words(word1, word2) {
return word1.concat(word2);
}

function concatenate(firstWord, secondWord, thirdWord) {
return firstWord.concat(" ", secondWord.concat(" ", 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.
}

console.log(concatenate("code", "your", "future"));
console.log(concatenate("I ", "like ", "pizza"));

/*
===================================================
======= TESTS - DO NOT MODIFY BELOW THIS LINE =====
Expand Down
20 changes: 17 additions & 3 deletions mandatory/4-tax.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,14 @@
Sales tax is 20% of the price of the product.
*/

function calculateSalesTax() {}

function calculateSalesTax(price) {
const itemTax = (price * 20) / 100;
const total = itemTax + price;
return total;
}
console.log(calculateSalesTax(15));
console.log(calculateSalesTax(17.5));
console.log(calculateSalesTax(34));
/*
CURRENCY FORMATTING
===================
Expand All @@ -17,7 +23,15 @@ function calculateSalesTax() {}
Remember that the prices must include the sales tax (hint: you already wrote a function for this!)
*/

function addTaxAndFormatCurrency() {}
function addTaxAndFormatCurrency(price) {
const itemTax = (price * 20) / 100;
const total = itemTax + 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.

as chatted int he meeting you could have used: calculateSalesTax(price)

return "£" + total.toFixed(2);
}

console.log(addTaxAndFormatCurrency(15));
console.log(addTaxAndFormatCurrency(17.5));
console.log(addTaxAndFormatCurrency(34));

/*
===================================================
Expand Down
12 changes: 9 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,21 @@
"url": "https://github.com/CodeYourFuture/JavaScript-Core-1-Coursework-Week1/issues"
},
"jest": {
"setupFilesAfterEnv": ["jest-extended"],
"setupFilesAfterEnv": [
"jest-extended"
],
"projects": [
{
"displayName": "mandatory",
"testMatch": ["<rootDir>/mandatory/*.js"]
"testMatch": [
"<rootDir>/mandatory/*.js"
]
},
{
"displayName": "extra",
"testMatch": ["<rootDir>/extra/*.js"]
"testMatch": [
"<rootDir>/extra/*.js"
]
}
]
},
Expand Down