Skip to content
This repository was archived by the owner on Jan 14, 2024. It is now read-only.
6 changes: 6 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"cSpell.words": [
"Sonjide",
"wordtrim"
]
}
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!! :D"

console.log(greeting);
console.log(greeting);
console.log(greeting);
3 changes: 3 additions & 0 deletions exercises/D-strings/exercise.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
// Start by creating a variable `message`
var message = "Message in a bottle";
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 = "Bonjour, je m'appelle ";
var myName = "Maha";

var greeting = greetingStart + myName;

console.log(greeting);
10 changes: 10 additions & 0 deletions exercises/F-strings-methods/exercise.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,13 @@
// Start by creating a variable `message`

var message;
var myName = "Maha";
var nameLength = myName.length;
message =
"My name is " +
myName +
" and my name is only " +
nameLength +
" characters long";

console.log(message);
5 changes: 5 additions & 0 deletions exercises/F-strings-methods/exercise2.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
const name = " Daniel ";
const nameTrim = name.trim();
const nameLength = nameTrim.length;

message =
"My name is " + nameTrim + " and my name is " + nameLength + " 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`

const numberOfStudents = 12;
const numberOfMentors = 9;

const total = numberOfStudents + numberOfMentors;

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

var totalNumber = numberOfMentors + numberOfStudents;

var studentPercentage = numberOfStudents / totalNumber * 100;
var mentorsPercentage = numberOfMentors / totalNumber * 100;

var roundedStudentPercentage = Math.round(studentPercentage);
var roundedMentorsPercentage = Math.round(mentorsPercentage);

console.log("Percentage student: " + roundedStudentPercentage + "%");
console.log("Percentage mentors: " + roundedMentorsPercentage + "%");
1 change: 1 addition & 0 deletions exercises/J-functions/exercise.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
function halve(number) {
// complete the function here
return number/2;
}

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

var result = triple(12);
Expand Down
3 changes: 2 additions & 1 deletion exercises/K-functions-parameters/exercise.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// Complete the function so that it takes input parameters
function multiply() {
function multiply(num1, num2) {
// Calculate the result of the function and return it
return num1 * num2;
}

// Assign the result of calling the function the variable `result`
Expand Down
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 a / b;
}

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 `${"Hello, my name is"} ${name}`;
}

var greeting = createGreeting("Daniel");

Expand Down
4 changes: 4 additions & 0 deletions exercises/K-functions-parameters/exercise4.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
// Declare your function first
function addNum(a, b) {
return a + b;
}

// 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(name, age){
return `${"Hello, my name is"} ${name} ${"and I'm"} ${age} ${"years old"}`;
}

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

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

//THIS SHOULD WORK!
function createGreeting(name) {
var greeting = `Helloooo ${name}`;
return greeting.toUpperCase();
}

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 idea of this exercise was to have 2 separate functions, one that returns the name in uppercase and another that returns the greeting by calling the first function to get the name


console.log(createGreeting(mentor1));
console.log(createGreeting(mentor2));
console.log(createGreeting(mentor3));
console.log(createGreeting(mentor4));
// console.log(createGreeting(mentor5));

//UPTO HERE

// // function CreateShoutyGreeting(){
// // return createGreeting.toUpperCase();
// // }

// CREATES ALL CAPS FOR A NAME and logs
// function createCapName(name){
// return name.toUpperCase();
// }
// // console.log(createCapName(mentor4));

// function createShoutyGreeting(name){
// var message = createCapName(name);
// return `Hello ${name}`;
// }
// console.log(createShoutyGreeting(mentor4));

13 changes: 10 additions & 3 deletions extra/1-currency-conversion.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@
Write a function that converts a price to USD (exchange rate is 1.4 $ to £)
*/

function convertToUSD() {}
function convertToUSD(pounds) {
return pounds * 1.4;
}

/*
CURRENCY FORMATTING
Expand All @@ -15,8 +17,13 @@ function convertToUSD() {}
They have also decided that they should add a 1% fee to all foreign transactions, which means you only convert 99% of the £ to BRL.
*/

function convertToBRL() {}

function convertToBRL(pounds) {
var brReal = pounds * 5.7;
var totalAfterFee = brazReal * 0.99;
var totalWithDec = totalAfterFee.toFixed(2);
var finalTotalFee = parseFloat(totalWithDec);
return finalTotalFee;
}
/* ======= TESTS - DO NOT MODIFY =====
There are some Tests in this file that will help you work out if your code is working.

Expand Down
12 changes: 6 additions & 6 deletions mandatory/1-syntax-errors.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
// 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;

return "The total is total";
total = a + b;
return "The total is " + total;
}

/*
Expand Down
9 changes: 4 additions & 5 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();
function getStringLength(word) {
return word.length;
}

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

/*
Expand Down
10 changes: 6 additions & 4 deletions mandatory/3-function-output.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,19 @@
// Add comments to explain what this function does. You're meant to use Google!
//My Comment - This function gives a random number by using math.random() and multiplying the value by 10

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Can you explain the range of the random numbers that will be returned? What range does Math.random() return, and so what will your method return?

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

// Add comments to explain what this function does. You're meant to use Google!

//My comment - The function combines two words using the concat method.
function combine2Words(word1, word2) {
return word1.concat(word2);
}

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}`;

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

can you do this using the .concat() method?

}
/*Can also be written this way:
return firstWord + " " + secondWord + " " + thirdWord; */

/*
===================================================
Expand Down
15 changes: 13 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(num) {
return num *1.2; //Adds 20% to number and gives total price including tax

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 could also declare 1.2 as a variable called priceWithTax or something similar, or even declare 0.2 as a variable call tax, and then multiply by the price and then add to the price. This would would make it easier to understand what your code is doing. However, your solution has the advantage of being concise. Both approaches work, so it's a matter of taste.

}

/*
CURRENCY FORMATTING
Expand All @@ -15,9 +17,18 @@ function calculateSalesTax() {}
Write a function that adds tax to a number, and then transforms the total into the format £0.00

Remember that the prices must include the sales tax (hint: you already wrote a function for this!)

*/

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

//CAN ALSO WRITE THIS WAY:
// function addTaxAndFormatCurrency(num) {
// var totalPrice= `£${calculateSalesTax(num).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.

Yes, as discussed in the previous comment, the first is more concise, but sometimes breaking your code down into stages and declaring variables with good names helps to make your code more understandable. It's up to you which you prefer.

// return totalPrice;
// }

/*
===================================================
Expand Down
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@
"url": "https://github.com/CodeYourFuture/JavaScript-Core-1-Coursework-Week1/issues"
},
"jest": {
"setupFilesAfterEnv": ["jest-extended"]
"setupFilesAfterEnv": [
"jest-extended"
]
},
"homepage": "https://github.com/CodeYourFuture/JavaScript-Core-1-Coursework-Week1#readme",
"devDependencies": {
Expand Down