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
2 changes: 1 addition & 1 deletion exercises/A-setup-ide/README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
There are some tools that will help you to write code. One of these, [Prettier](https://prettier.io/), formats your code, making it easier for you and others to read.
There are some tools that will help you to write code. One of these, [Prettier](https:react//prettier.io/), formats your code, making it easier for you and others to read.

### 1. Install prettier

Expand Down
5 changes: 5 additions & 0 deletions exercises/B-hello-world/exercise.js
Original file line number Diff line number Diff line change
@@ -1 +1,6 @@
console.log("Hello world");
console.log("cd exercises/B-hello-world")
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Interesting test! I hope you realised that this will still just print "cd exercises/B-hello-world", even if this command has a very different meaning when you run it in the console, that is, this will not change directory when run inside the console.log as a string.

console.log(`This is my first coding week`)
console.log('Hello World. I just started learning JavaScript!')
console.log(29)

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`
const greeting="Hello world";

console.log(greeting);
console.log(greeting);
console.log(greeting);
6 changes: 4 additions & 2 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`

console.log(message);
let message="This is a string"
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 first="Hello, my name is "
let myName="Mari"
let message=first+myName
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 how you concatenated the first+myName in the variable. I did it the very long way.... This is good.

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 myName="mari"
let lengthName=myName.length
let message="My name is "+myName+" and my name is " + lengthName+" characters long"
console.log(message);

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

console.log(message);
let myName="mari"
let lengthName=myName.length
// let messageTwo=`my name is${myName}and my name is${lengthName}characters long`
let message=" My name is"+myName+" and my name is " + lengthName+" characters long"
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 a very small comment, but you should try to be consistent with your style. If you are putting spaces before and after the plus signs, for example. is" + myName + " an you should do that for all strings concatenations.

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 used the .trim method to remove the extra whitespace for this I made space. so I should do that for all strings concatenations??

Copy link
Copy Markdown

@Gayle-Thompson-Igwebike Gayle-Thompson-Igwebike Dec 1, 2022

Choose a reason for hiding this comment

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

Thanks @mcarballopacheco Your suggestion is quite right. I'm practising consistency also. Javascript is soo hard for me

console.log(message.trim());
6 changes: 6 additions & 0 deletions exercises/G-numbers/exercise.js
Original file line number Diff line number Diff line change
@@ -1 +1,7 @@
// Start by creating a variables `numberOfStudents` and `numberOfMentors`
let numberOfStudents=15;
let numberOfMentors=8;
let total=numberOfMentors+numberOfStudents
console.log(numberOfStudents)
console.log(numberOfMentors)
console.log(total)
9 changes: 7 additions & 2 deletions exercises/I-floats/exercise.js
Original file line number Diff line number Diff line change
@@ -1,2 +1,7 @@
var numberOfStudents = 15;
var numberOfMentors = 8;
let numberOfStudents = 15;
let numberOfMentors = 8;
let total=numberOfMentors+numberOfStudents
let percentageOfStudent=numberOfStudents/total*100;
console.log("Percentage students: "+Math.round(percentageOfStudent)+"%");
let PercentageMentors=100-percentageOfStudent
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 have also calculated the percentage of mentors, as.
let PercentageMentors=numberOfMentors/total*100;
and then use round. Surprisingly, this may not always be the same as the way you calculated it, because if the fraction ends in 0.5, it will always go up to the next integer when using Math.round. This is why in general, it is important to be aware and careful when rounding up numbers.

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 got it thanks.

console.log("Percentage mentors: "+Math.round(PercentageMentors)+"%");
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/2
}

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

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*3
}

var result = triple(12);
Expand Down
2 changes: 1 addition & 1 deletion exercises/K-functions-parameters/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ function add(num1, num2) {
## Expected result

```
Hello, my name is Daniel
Hello,my name is ;Daniel
```

## Exercise 4
Expand Down
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,5 +1,7 @@
// Declare your function first

function divide(num1,num2) {
return num1 / num2;
}
var result = divide(3, 4);

console.log(result);
6 changes: 4 additions & 2 deletions exercises/K-functions-parameters/exercise3.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
// Write your function here
function greeting(name){
console.log("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.

I think here it would have make more sense based on the exercise to return the greeting and then use console.log() outside of the function.

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.

function greeting(name){
return name;
}
console.log("Hello,my name is ;"+greeting("Daniel"));

Is it ok?

}
greeting("Daniel")

var greeting = createGreeting("Daniel");

console.log(greeting);
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 sum(num1,num2){
return num1+num2
}
// Call the function and assign to a variable `sum`

console.log(sum);
console.log(sum(13,124));
Copy link
Copy Markdown

@mcarballopacheco mcarballopacheco Dec 1, 2022

Choose a reason for hiding this comment

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

This will work, but in the exercise it mentioned to assign the value to a variable called sum, so:
let sum = add(13, 124)
console.log(sum)

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

const greeting = createLongGreeting("Daniel", 30);
function createLongGreeting(name,age){
return "Hello ,my name is "+name+"and i'm "+age+ " years old"
}
const greeting = createLongGreeting("Daniel", 30);

console.log(greeting);
23 changes: 18 additions & 5 deletions exercises/L-functions-nested/exercise.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,18 @@
var mentor1 = "Daniel";
var mentor2 = "Irina";
var mentor3 = "Mimi";
var mentor4 = "Rob";
var mentor5 = "Yohannes";

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

function nameToUpperCase(name){
return name.toUpperCase();
}
function greeting(name){
return `Hello ${nameToUpperCase(name)}`;
}
function result(name){
return console.log(greeting(name));
}
result(mentor1);
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 looks great!

result(mentor3)
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,11 @@
Write a function that converts a price to USD (exchange rate is 1.4 $ to £)
*/

function convertToUSD() {}
function convertToUSD(price) {
return price*1.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.

I like this syntax...mine was sooo long... Great job.

}
console.log(convertToUSD(32))
console.log(convertToUSD(50))

/*
CURRENCY CONVERSION
Expand All @@ -15,8 +19,11 @@ 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(price) {
return price*5.7*0.99
}
console.log(convertToBRL(30))
console.log(convertToBRL(1.5))
/* ======= TESTS - DO NOT MODIFY =====
There are some Tests in this file that will help you work out if your code is working.

Expand Down
16 changes: 10 additions & 6 deletions extra/2-piping.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,21 +16,25 @@
the final result to the variable goodCode
*/

function add() {

function add(number1,number2) {
return number1+number2
}
console.log(add(1,3))

function multiply() {

function multiply(number1,number2) {
return number1*number2
}
console.log(multiply(2,3))

function format() {

function format(number) {
return `£${number}`
}
console.log(format(16))

const startingValue = 2;

// Why can this code be seen as bad practice? Comment your answer.
//there are three functions that are not necessary and I think it is possible with a shorter code as well.(I am not sure!!!!!!!!!!!!!!!!!)
let badCode =

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

It is in general a bad idea to call many functions in the same line. It makes the code very hard to read. A better idea is to call each function once in a line and assign the result to a variable which then gets called in the following like but the next function, etc.

/* BETTER PRACTICE */
Expand Down
20 changes: 12 additions & 8 deletions mandatory/1-syntax-errors.js
Original file line number Diff line number Diff line change
@@ -1,19 +1,23 @@
// 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 getTotal(a, b) {
total = a ++ b;

return "The total is total";
}
function introduceMe(name, age){
// return `Hello ,my name is ${name} and I am ${age} years old`;

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


/*
function getTotal(a,b) {
let total = a + b;
return `The total is ${total}`;}

/*
===================================================
======= TESTS - DO NOT MODIFY BELOW THIS LINE =====

Expand Down
19 changes: 12 additions & 7 deletions mandatory/2-logic-error.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,23 @@
// The syntax for this function is valid but it has an error, find it and fix it.

function trimWord(word) {
return wordtrim();
function trimWord(word){
return word.trim();
}
// console.log(trimWord(" CodeYourFuture" ))
// console.log(trimWord(" CodeYourFuture teaches coding "))

function getStringLength(word) {
return "word".length();
function getStringLength(word){
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(2,3,6)
// console.log(2,3,4)
/*
===================================================
======= TESTS - DO NOT MODIFY BELOW THIS LINE =====
Expand Down
7 changes: 7 additions & 0 deletions mandatory/3-function-output.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,24 @@
// Add comments to explain what this function does. You're meant to use Google!
//The Math.random() function returns a floating-point, pseudo-random number that's greater than or equal to 0 and less than 1,
function getRandomNumber() {
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 here, the question is asking what does the getRandomNumber() does also?

return Math.random() * 10;
}

// Add comments to explain what this function does. You're meant to use Google!
//The concat() method is used to merge two or more arrays or any number or string. This method does not change the existing arrays, but instead returns a new array.in this example with concat word1 and word2 coming next to gether.
function combine2Words(word1, word2) {
return word1.concat(word2);
}

function concatenate(firstWord, secondWord, thirdWord) {
return firstWord.concat(" " + secondWord).concat(" " + thirdWord);
// return firstWord.concat(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.
}
// console.log(concatenate(code,your,future))
// console.log(concatenate(I,like,pizza))
// console.log(concatenate(I,am,13))

/*
===================================================
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,8 +5,12 @@
Sales tax is 20% of the price of the product.
*/

function calculateSalesTax() {}

function calculateSalesTax(price) {
return price*1.2
}
console.log(calculateSalesTax(15));
console.log(calculateSalesTax(17.50));
console.log(calculateSalesTax(34));
/*
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(price) {
return `£${(price * 1.2).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.

You should have used the calculateSalesTax function that you just created. The reason we create functions is to not repeat code which minimises errors. For example, let say the sales tax changes from 20% to 25%. if all of the times you calculated the sales tax you always use the calculateSalesTax function, then you only need to change the calculation in one place only. But if you are calculating in different places, then you would have to find them one by one.

}

console.log(addTaxAndFormatCurrency(15))
console.log(addTaxAndFormatCurrency(17.5))
console.log(addTaxAndFormatCurrency(34))
/*
===================================================
======= TESTS - DO NOT MODIFY BELOW THIS LINE =====
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