Skip to content

Commit d6c5c0b

Browse files
committed
Described what line 3 is doing
1 parent 8f3d6cf commit d6c5c0b

File tree

12 files changed

+102
-11
lines changed

12 files changed

+102
-11
lines changed

Sprint-1/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+
// Line 3 returns the incremented value of count. The operator = assigns count +1 to the varibale count in the
8+
// left.

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,9 @@ let 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-
let initials = ``;
8+
let initials = firstName[0]+middleName[0]+lastName[0];
9+
10+
console.log(initials)
911

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

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@ 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(lastSlashIndex+1);
21+
const ext = base.slice(base.lastIndexOf(".") + 1);
2222

23+
console.log(dir)
2324
// https://www.google.com/search?q=slice+mdn

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

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,18 @@ 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+
// num represents the result of equation at the right hand side of the operator =
13+
14+
// Step-1 ---> Math.random() generates a random decimal,
15+
// Step-2 ---> (maximum-minumum +1) is evaluated
16+
// Step-3 ---> Math.random() is multiplied by (maximum-minumum +1)
17+
// Step-4 ---> the resukt of Step-3 is round by the method Math.floor
18+
// Step-5 ---> minimum is added to the result of Step-4
19+
20+
// Thus, num represents random numbers generated between minimum 1 and maximum 100. As we run the code several times it
21+
// generates new numbers.
22+
23+
24+
console.log(num);

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

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,5 @@
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 have solved it by adding two forward slashes (//) at the beginning of each line.
5+
// The computer does not run this line too.

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

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

3-
const age = 33;
3+
//const age = 33;
4+
5+
// we need to replace "const" with "let"
6+
7+
let age = 33;
48
age = age + 1;
9+
10+
11+
console.log(age);

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
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}`);
4+
// The variable cityOfBirth was called before it was defined, so we need to bring that variable first
55
const cityOfBirth = "Bolton";
6+
console.log(`I was born in ${cityOfBirth}`);
7+

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

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,20 @@
11
const cardNumber = 4533787178994213;
2-
const last4Digits = cardNumber.slice(-4);
2+
//const last4Digits = cardNumber.slice(-4);
3+
4+
const last4Digits = cardNumber.toString().slice(-4);
5+
6+
7+
console.log(last4Digits);
38

49
// The last4Digits variable should store the last 4 digits of cardNumber
510
// However, the code isn't working
611
// Before running the code, make and explain a prediction about why the code won't work
712
// Then run the code and see what error it gives.
813
// Consider: Why does it give this error? Is this what I predicted? If not, what's different?
914
// Then try updating the expression last4Digits is assigned to, in order to get the correct value
15+
16+
// I think the code does not work because cardNumber variable is not stored as string.
17+
18+
// My guess was right.
19+
20+
// Therefore first we need to change CardNumber variable into string before we use the slice method.

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

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,14 @@
11
const 12HourClockTime = "20:53";
2-
const 24hourClockTime = "08:53";
2+
const 24hourClockTime = "08:53";
3+
4+
// Alternatively the above variable names can be corrected as follows:
5+
6+
// Option-1
7+
8+
const twelveHourClockTime = "20:53";
9+
const twentyFourHourClockTime = "08:53";
10+
11+
// Option -2
12+
13+
const hour12ClockTime = "20:53";
14+
const hour24ClockTime = "08:53";

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

Lines changed: 13 additions & 1 deletion
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,23 @@ 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+
16+
// Ans: There are five (5) function calls, Line 4 Number() and replaceAll(), Line 5, Number() and replaceAll()
17+
// Line 10 log().
1518

1619
// 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?
1720

21+
// Ans: The error is coming from line 5 "("," ""));"" a comma was missing. Putting a comma solved the problem.
22+
1823
// c) Identify all the lines that are variable reassignment statements
24+
25+
// Ans: Line 4 carPrice and Line 5 priceAfterOneyear are variable reassignments.
1926

2027
// d) Identify all the lines that are variable declarations
2128

29+
// Ans: 4 variable declaration Line 1, Line 2, Line 7 and Line 8
30+
2231
// e) Describe what the expression Number(carPrice.replaceAll(",","")) is doing - what is the purpose of this expression?
32+
33+
// Ans: The purpose of the expression Number(carPrice.replaceAll(",","")) is to change a string argument the contains commas passed to replaceAll()
34+
// function into number, first the function replaceAll() removes the commas and then the function Number() changes it into number.

0 commit comments

Comments
 (0)