Skip to content

Commit 8987610

Browse files
Complete Sprint 1 Exercises
1 parent b31a586 commit 8987610

14 files changed

Lines changed: 39 additions & 17 deletions

File tree

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 adds 1 to 'count'
8+
// The = operator gives the new value to 'count'.

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

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ 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 = ``;
9-
10-
// https://www.google.com/search?q=get+first+character+of+string+mdn
8+
let initials = firstName[0] + middleName[0] + lastName[0];
119

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

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

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ 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 = ;
22-
20+
const dir = filePath.slice(0, lastSlashIndex);
21+
const ext = filePath.slice(filePath.lastIndexOf("."));
2322
// https://www.google.com/search?q=slice+mdn

Sprint-1/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+
// num represents a random number between minimum and maximum.
11+
// Math.random() generates a random number , and Math.floor() rounds it down to a whole number.
12+
// Expression (maximum-minimum+1) gives the range of numbers between minimum and maximum.
13+
// On the final line, on the random number will add the minimum value , and that's ensure that the random number is always between minimum and maximum.

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+
SyntaxError: Unexpected identifier 'is'. JavaScript tries to read the text as code, but it is not valid.
4+
Add // at the beginning of each line make them comments.

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

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

33
const age = 33;
44
age = age + 1;
5+
// The above code has a TypeError:Assignment to constant variable.
6+
//The error is because age is declared as a constant variable, which mean cannot be reassigned. To fix this error, we can declare age as a let variable 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+
// The error is a ReferenceError: Cannot access 'cityOfBirth' before initialization. The error happens because cityOfBirth is used before it is declared. We can fix this error by moving the const cityOfBirth line before console.log().

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,5 @@ 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+
// I think the code won't work because the slice() works only on strings, and cardNumber is a number.
11+
// The error says that slice() its not a function because cardNumber is a number. Converting it to a string("4533787178994213") will fix the problem.

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
const 12HourClockTime = "8:53pm";
22
const 24hourClockTime = "20:53";
3+
// SyntaxError:Invalid or unexpected token. This error is because the variable name starts with a number. Variable name cannot start with a number in JavaScript.We can fix the error by using a valid variable const twelveHourClockTime.

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

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,12 @@ 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+
// There are 5 function calls in this file. The function calls are made on the following lines: replaceAll() line 4, Number() line 4, replaceAll() line 5, Number() line 5, console.log() line 10.
1616
// 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-
17+
// The error is coming from line 5. The error appears because there is a missing comma in the replaceAll() function. We can fix the problem by adding a comma in the replaceAll() function on line 5.
1818
// c) Identify all the lines that are variable reassignment statements
19-
19+
// The lines that are variable reassignment statements are line 4 and line 5.
2020
// d) Identify all the lines that are variable declarations
21-
21+
// The variable declarations are on line 1, line 2, line 7 and line 8.
2222
// e) Describe what the expression Number(carPrice.replaceAll(",","")) is doing - what is the purpose of this expression?
23+
//The expression removes the comma from the string from carPrice and converts the string to a number.

0 commit comments

Comments
 (0)