Skip to content

Commit 22e0557

Browse files
committed
completed Sprint 2 tasks
1 parent d28242a commit 22e0557

14 files changed

Lines changed: 68 additions & 16 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: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,11 @@ console.log(`The base part of ${filePath} is ${base}`);
1717
// Create a variable to store the dir part of the filePath variable
1818
// Create a variable to store the ext part of the variable
1919

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

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

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,7 @@ 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+
// Answer: For calculations i utilised BODMAS formula solving numbers in brackets first, multiplication, subtraction and addition
12+
// I used 0.68 for math.floor(random number) + 1
13+
// 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: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,8 @@
22

33
const 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: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
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+
// The error is ReferenceError: Cannot access 'cityOfBirth' before initialization
8+
// Answer: I switched the order by declaring the const first before calling /printing

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,8 @@ 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+
11+
//Prediction was the code would run successfully without error although with the wrong results due to absence of syntax errors in the file
12+
// Error returned: TypeError: cardNumber.slice is not a function
13+
// Lesson learnt here; slice method is only available for strings or arrays not numbers
14+
// 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)