Skip to content

Commit 172ac8f

Browse files
I added an explination descriping what is line 3 and the operator = doing. for File 1 in exercises.
1 parent 30a9b02 commit 172ac8f

File tree

8 files changed

+25
-8
lines changed

8 files changed

+25
-8
lines changed

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ count = count + 1;
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
77

8-
// line 3 is updating the value of the count variable by adding 1 to its current value.
9-
// The = opperator is an assignment opperator that assigns the result of the expression on the right (count+1) to the varibale on the left (count).
10-
// so, if count was 0 befor line 3 is excuted it will be 1 after line 3 is excuted.
11-
// And if it was 1 it will be 2 after line 3 is excuted.
8+
line 3 is updating the value of the count variable by adding 1 to its current value.
9+
The = opperator is an assignment opperator that assigns the result of the expression on the right (count+1) to the varibale on the left (count).
10+
so, if count was 0 befor line 3 is excuted it will be 1 after line 3 is excuted.
11+
And if it was 1 it will be 2 after line 3 is excuted.

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ 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]);
99

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

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,5 @@ 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+
num represents a random integer between the minimum and maximum values (inclusive).

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,4 @@
11
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?
2+
We don't want the computer to run these 2 lines - how can we solve this problem?
3+
4+
comment it out using // at the start of each line, or use /* at the start and */ at the end to comment out a block of code.

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,7 @@
22

33
const age = 33;
44
age = age + 1;
5+
in this code we are trying to reassign the value of age variable by adding 1 to ImageTrack.
6+
However, this will result in an error because the age variable is diclared as a constant using the const keyword.
7+
And in javascript, a variable decalred with const cannot be readdigned a new value afteer it has been intialised ,
8+
so if we want to reassign the vlaue we have to use let instead.

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,4 @@
33

44
console.log(`I was born in ${cityOfBirth}`);
55
const cityOfBirth = "Bolton";
6+
Because the const varibale is decalred after it is used in the console={.log} statement and it should be decalred befor to be executed.

Sprint-1/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);
34

45
// The last4Digits variable should store the last 4 digits of cardNumber
56
// However, the code isn't working
67
// Before running the code, make and explain a prediction about why the code won't work
78
// Then run the code and see what error it gives.
89
// Consider: Why does it give this error? Is this what I predicted? If not, what's different?
910
// Then try updating the expression last4Digits is assigned to, in order to get the correct value
11+
12+
I exepected first that the .slice negative value (-4) will count from the beganning and drob of the first four Number.
13+
When I run the code the error was that the cardNumber is not a function,
14+
so I thought that I might need to turn the code into a function,
15+
but when I checked an AI toolbarit showed that .slice is a methode that is used for string and array ,
16+
so the card number should turned into a string by addint .tostring after the card number and then use the .slice method to get the last 4 last4Digits.

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
const 12HourClockTime = "20:53";
2-
const 24hourClockTime = "08:53";
2+
const 24hourClockTime = "08:53";
3+
In javascript variabl names should not start with a Number.

0 commit comments

Comments
 (0)