Skip to content

Commit 877e0de

Browse files
committed
I worked in all the excercises
1 parent d28242a commit 877e0de

12 files changed

Lines changed: 136 additions & 22 deletions

File tree

‎Sprint-2/1-key-exercises/1-count.js‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,4 @@ count = count + 1;
44

55
// Line 1 is a variable declaration, creating the count variable with an initial value of 0
66
// Describe what line 3 is doing, in particular focus on what = is doing
7+
//a variable is initialised and assigned a value zero, than it was reassigned additing 1 to its value.

‎Sprint-2/1-key-exercises/2-initials.js‎

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,18 @@ const lastName = "Johnson";
55
// Declare a variable called initials that stores the first character of each string.
66
// This should produce the string "CKJ", but you must not write the characters C, K, or J in the code of your solution.
77

8-
const initials = ``;
8+
//const initials = ``;
99

1010
// https://www.google.com/search?q=get+first+character+of+string+mdn
11+
12+
const initials = `${firstName[0]}${middleName[0]}${lastName[0]}`;
13+
14+
console.log(initials); // Output: CKJ
15+
16+
17+
18+
19+
20+
21+
22+

‎Sprint-2/1-key-exercises/3-paths.js‎

Lines changed: 43 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,52 @@
99

1010
// (All spaces in the "" line should be ignored. They are purely for formatting.)
1111

12+
//const filePath = "/Users/mitch/cyf/Module-JS1/week-1/interpret/file.txt";
13+
//const lastSlashIndex = filePath.lastIndexOf("/");
14+
//const base = filePath.slice(lastSlashIndex + 1);
15+
//console.log(`The base part of ${filePath} is ${base}`);
16+
17+
// Create a variable to store the dir part of the filePath variable
18+
// Create a variable to store the ext part of the variable
19+
20+
21+
//const dir = ;
22+
//const ext = ;
23+
24+
// https://www.google.com/search?q=slice+mdn
25+
26+
// from here start my explaination of the code I see for education purposes.
27+
// this is a file system that allows users to manipulate what files they see and what information they omit, and they use string
28+
//methods to do that
29+
// most common methods developers use to manipulate the files are included in this file Sprint-2\1-key-exercises\manipulating files.txt
30+
31+
// in this example the string methods are used to manipulate the file system
32+
1233
const filePath = "/Users/mitch/cyf/Module-JS1/week-1/interpret/file.txt";
13-
const lastSlashIndex = filePath.lastIndexOf("/");
14-
const base = filePath.slice(lastSlashIndex + 1);
15-
console.log(`The base part of ${filePath} is ${base}`);
34+
// a variable is created to store the file path of a file in the file system
35+
//const lastSlashIndex = filePath.lastIndexOf("/");
36+
// a variable is created and identified to find the last occurance of the "/" character in the filePath variable, which is used to separate directories and files in a file system
37+
//const base = filePath.slice(lastSlashIndex + 1);
38+
// a variable is created and identified to extract the base part of the filePath variable, which is the name of the file and its extension, by using the slice method
39+
//console.log(`The base part of ${filePath} is ${base}`);
40+
// console.log is used to print the base part of the filePath variable to the console, which is the name of the file and its extension
1641

1742
// Create a variable to store the dir part of the filePath variable
1843
// Create a variable to store the ext part of the variable
1944

20-
const dir = ;
21-
const ext = ;
45+
const lastSlashIndex = filePath.lastIndexOf("/");
46+
// here we have the variable lastslashIndex already created and identified its position
47+
// stores the position or (index) of "/" in filePath, so this "/" is used as a symbol that storers the number index or a place that seprate dir from base
48+
const dir = filePath.slice(0, lastSlashIndex);
49+
console.log(dir);
50+
// we show our result in the console
51+
const lastDotIndex = filePath.lastIndexOf('.');
52+
// we create a variable and assign its value using the indexOf to be from the dot location
53+
const ext = filePath.slice(lastDotIndex);
54+
// we create a variable where we assign its value using the slice method to be from the dot only
2255

23-
// https://www.google.com/search?q=slice+mdn
56+
console.log(ext)
57+
// we print our result in the console
58+
//slice(startIndex, endIndex)
59+
// means, start here and stop here. we are doing this to seprate the dir from base so we need to tell it where to start and where to end, hence that is why we use slice method,
60+
// my comments needs correcting to look profissional -_-

‎Sprint-2/1-key-exercises/4-random.js‎

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,16 @@ const num = Math.floor(Math.random() * (maximum - minimum + 1)) + minimum;
77
// Try breaking down the expression and using documentation to explain what it means
88
// It will help to think about the order in which expressions are evaluated
99
// Try logging the value of num and running the program several times to build an idea of what the program is doing
10+
11+
12+
//here starts my learning
13+
14+
// first const minimun, const maximum are the variables
15+
// = the assignmen operator
16+
// what comes after = is what the variable will store
17+
// Math.floor is a method and here we are telling it that its argument is to use the random method
18+
// and multiply the result before rounding with the maximum and minimum variables we created
19+
// * is a multiplication operator
20+
// to understand what is going on we need to understand what the floor and random methods do
21+
//Math.floor (rounds down to the nearest whole number) and than pass it to Math.floor
22+
// we are asking the program to round whatever result we have to the nearest whole number

‎Sprint-2/2-mandatory-errors/0.js‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,4 @@
1-
This is just an instruction for the first activity - but it is just for human consumption
2-
We don't want the computer to run these 2 lines - how can we solve this problem?
1+
//This is just an instruction for the first activity - but it is just for human consumption
2+
//We don't want the computer to run these 2 lines - how can we solve this problem?
3+
4+
//we use slash to comment it. So the computer doesn't excute the text.

‎Sprint-2/2-mandatory-errors/1.js‎

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,10 @@
11
// trying to create an age variable and then reassign the value by 1
22

3-
const age = 33;
3+
let age = 33;
44
age = age + 1;
5+
6+
//we change the variable declaration and reassign its value
7+
// variable declaration keywords
8+
// const can't be used to reassign a value
9+
// let can be used to reassign a value
10+

‎Sprint-2/2-mandatory-errors/2.js‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,5 @@
33

44
console.log(`I was born in ${cityOfBirth}`);
55
const cityOfBirth = "Bolton";
6+
7+
// the variable was declared after the print function so the program doesn't know what is cityofBirth. Therefore it can't perform the print function or excuted before declaring the variable

‎Sprint-2/2-mandatory-errors/3.js‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,4 @@ const last4Digits = cardNumber.slice(-4);
77
// Then run the code and see what error it gives.
88
// Consider: Why does it give this error? Is this what I predicted? If not, what's different?
99
// Then try updating the expression last4Digits is assigned to, in order to get the correct value
10+
// in this case its a reference error the program is trying to access a value that wasn't declared. In this case a variable.

‎Sprint-2/2-mandatory-errors/4.js‎

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,6 @@
1-
const 12HourClockTime = "8:53pm";
2-
const 24hourClockTime = "20:53";
1+
const TwelveHourClockTime = "8:53pm";
2+
const TwentyFourHourClockTime = "20:53";
3+
// an identifier or keyword can't follow a numeric literal. We fix this by writing the numbers in words format
4+
5+
//const 12HourClockTime = "8:53pm";
6+
//const 24hourClockTime = "20:53";

‎Sprint-2/3-mandatory-interpret/1-percentage-change.js‎

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ let carPrice = "10,000";
22
let priceAfterOneYear = "8,543";
33

44
carPrice = Number(carPrice.replaceAll(",", ""));
5-
priceAfterOneYear = Number(priceAfterOneYear.replaceAll("," ""));
5+
priceAfterOneYear = Number(priceAfterOneYear.replaceAll(",", ""));
66

77
const priceDifference = carPrice - priceAfterOneYear;
88
const percentageChange = (priceDifference / carPrice) * 100;
@@ -11,12 +11,16 @@ console.log(`The percentage change is ${percentageChange}`);
1111

1212
// Read the code and then answer the questions below
1313

14-
// a) How many function calls are there in this file? Write down all the lines where a function call is made
1514

15+
// a) How many function calls are there in this file? Write down all the lines where a function call is made
16+
//5 FUNCTION calls. Line 4, 5, 10.
1617
// b) Run the code and identify the line where the error is coming from - why is this error occurring? How can you fix this problem?
17-
18+
//The error is coming from line 5, column 61. Thhere is nothing seprating the two indexes. A comma can be used to seprate them.
1819
// c) Identify all the lines that are variable reassignment statements
19-
20+
//Two lines 4 and 5
2021
// d) Identify all the lines that are variable declarations
21-
22+
//four lines 1,2,7,8
2223
// e) Describe what the expression Number(carPrice.replaceAll(",","")) is doing - what is the purpose of this expression?
24+
//The replace.all method is used to include the car price and the price after one year of depreciation.
25+
//The purpose of the expression is to take the price string and search for every comma and replace it
26+
// we are saying replace this "," , with this "" and because of the empty string it means without a comma

0 commit comments

Comments
 (0)