Skip to content

Commit 2ad51f8

Browse files
committed
renamed branch and pushed files to a previous branch long story
1 parent 0f5f4e2 commit 2ad51f8

12 files changed

Lines changed: 80 additions & 27 deletions

File tree

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,5 @@ 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+
8+
//Answer: The = means assignment. The value of count is 0 but it increments by 1
Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,14 @@
11
const firstName = "Creola";
22
const middleName = "Katherine";
33
const lastName = "Johnson";
4+
// const initial = "initials";
5+
// const index = 1;
46

7+
// console.log('The ${Initial} ${index} is ${firstName.charAt(index)}');
58
// Declare a variable called initials that stores the first character of each string.
69
// This should produce the string "CKJ", but you must not write the characters C, K, or J in the code of your solution.
710

8-
const initials = ``;
11+
const initials = firstName[0] + middleName[0] + lastName[0];
12+
console.log(initials);
913

1014
// https://www.google.com/search?q=get+first+character+of+string+mdn

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

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,16 @@ const filePath = "/Users/mitch/cyf/Module-JS1/week-1/interpret/file.txt";
1313
const lastSlashIndex = filePath.lastIndexOf("/");
1414
const base = filePath.slice(lastSlashIndex + 1);
1515
console.log(`The base part of ${filePath} is ${base}`);
16+
// console.log('The dir path of ${dir} is ${filePath}.${lastSlashIndex}');
17+
1618

1719
// Create a variable to store the dir part of the filePath variable
1820
// Create a variable to store the ext part of the variable
1921

20-
const dir = ;
21-
const ext = ;
22+
const dir = filePath.slice(0, lastSlashIndex);
23+
const ext = base.slice(base.lastIndexOf("."));
24+
25+
console.log(`The dir part of ${filePath} is ${dir}`);
26+
console.log(`The ext part of ${base} is ${ext}`);
2227

2328
// https://www.google.com/search?q=slice+mdn

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,14 @@ const minimum = 1;
22
const maximum = 100;
33

44
const num = Math.floor(Math.random() * (maximum - minimum + 1)) + minimum;
5+
// (0.68 * 100 ) + 1
6+
console.log(num)
57

68
// In this exercise, you will need to work out what num represents?
79
// Try breaking down the expression and using documentation to explain what it means
810
// It will help to think about the order in which expressions are evaluated
911
// Try logging the value of num and running the program several times to build an idea of what the program is doing
12+
13+
// Answer: For calculations i utilised BODMAS formula solving numbers in brackets first, multiplication, subtraction and addition
14+
// I used 0.68 for math.floor(random number) + 1
15+
// Sum = 69

‎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+
// I have commented out the lines. The computer removes commented lines from code compilation

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

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
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+
console.log(age)
7+
8+
// The TypeError: Assignment to constant variable implies we are trying to reassign the variable twice.
9+
// This case, I have used let instead in order to allow the variable to be reused.

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
// Currently trying to print the string "I was born in Bolton" but it isn't working...
22
// what's the error ?
33

4-
console.log(`I was born in ${cityOfBirth}`);
54
const cityOfBirth = "Bolton";
5+
console.log(`I was born in ${cityOfBirth}`);
6+
7+
8+
// The error is ReferenceError: Cannot access 'cityOfBirth' before initialization
9+
// Answer: I switched the order by declaring the const first before calling /printing

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

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,16 @@
11
const cardNumber = 4533787178994213;
2-
const last4Digits = cardNumber.slice(-4);
2+
const last4Digits = cardNumber.toString().slice(-4);
3+
console.log(last4Digits)
4+
35

46
// The last4Digits variable should store the last 4 digits of cardNumber
57
// However, the code isn't working
68
// Before running the code, make and explain a prediction about why the code won't work
79
// Then run the code and see what error it gives.
810
// Consider: Why does it give this error? Is this what I predicted? If not, what's different?
911
// Then try updating the expression last4Digits is assigned to, in order to get the correct value
12+
13+
//Prediction was the code would run successfully without error although with the wrong results due to absence of syntax errors in the file
14+
// Error returned: TypeError: cardNumber.slice is not a function
15+
// Lesson learnt here; slice method is only available for strings or arrays not numbers
16+
// So converted the cardNumber into a string first

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

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,7 @@
1-
const 12HourClockTime = "8:53pm";
2-
const 24hourClockTime = "20:53";
1+
const twelveHourClockTime = "8:53pm";
2+
const twentyFourHourClockTime = "20:53";
3+
console.log(twelveHourClockTime);
4+
console.log(twentyFourHourClockTime);
5+
6+
// Error - SyntaxError: Invalid or unexpected token
7+
// lesson learnt - variables cannot start with a number

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

Lines changed: 13 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;
@@ -12,11 +12,19 @@ console.log(`The percentage change is ${percentageChange}`);
1212
// Read the code and then answer the questions below
1313

1414
// a) How many function calls are there in this file? Write down all the lines where a function call is made
15-
15+
// 2
16+
//carPrice = Number(carPrice.replaceAll(",", ""));
17+
//priceAfterOneYear = Number(priceAfterOneYear.replaceAll("," ","));
1618
// 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-
19+
//b) error = SyntaxError: missing ) after argument list
20+
// (",", ",")); - added , between quoted values
1821
// c) Identify all the lines that are variable reassignment statements
19-
22+
//carPrice = Number(carPrice.replaceAll(",", ""));
23+
//priceAfterOneYear = Number(priceAfterOneYear.replaceAll("," ","));
2024
// d) Identify all the lines that are variable declarations
21-
25+
//let carPrice = "10,000";
26+
//let priceAfterOneYear = "8,543";
27+
//const priceDifference = carPrice - priceAfterOneYear;
28+
//const percentageChange = (priceDifference / carPrice) * 100;
2229
// e) Describe what the expression Number(carPrice.replaceAll(",","")) is doing - what is the purpose of this expression?
30+
// e) cleans the amount format by removing characters such as , and leaving only number

0 commit comments

Comments
 (0)