Skip to content

Commit 719ac38

Browse files
completed tasks on key-exercises, mandatory-errors
1 parent f5b9e81 commit 719ac38

9 files changed

Lines changed: 30 additions & 8 deletions

File tree

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,4 @@ 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 is updating the value of the count variable by adding 1 to the current value of count. The = operator is used to assign the new value (count + 1) back to the count variable, effectively incrementing its value by 1.

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,6 @@ const 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-
const initials = ``;
8+
const initials = firstName[0] + middleName[0] + lastName[0]; // the expected output is "CKJ"
99

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

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ console.log(`The base part of ${filePath} is ${base}`);
1616

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
19+
const lastDotIndex = base.lastIndexOf(".");
20+
const dir = filePath.slice(0, lastSlashIndex);
21+
const ext = base.slice(lastDotIndex + 1, base.length);
1922

20-
const dir = ;
21-
const ext = ;
22-
23-
// https://www.google.com/search?q=slice+mdn
23+
// https://www.google.com/search?q=slice+mdn

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ const maximum = 100;
44
const num = Math.floor(Math.random() * (maximum - minimum + 1)) + minimum;
55

66
// In this exercise, you will need to work out what num represents?
7+
// num is a random integer between the minimum and maximum values (inclusive) and is a calculated value from this clearly explained expression below.
78
// Try breaking down the expression and using documentation to explain what it means
9+
/*The expresssion Math.random() generates a random floating-point number between 0 (inclusive) and 1 (inclusive). By multiplying this value by (maximum - minimum + 1), we scale it to the desired range. The Math.floor() function is then used to round down to the nearest whole number, and finally, we add the minimum value to shift the range to start from the minimum value instead of 0. The expected result is always a whole number between the minimum of 1 and the maximum of 101 (inclusive).*/
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

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
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+
// by commenting out these two lines using // for single-line comments or /* */ for multi-line comments, we can prevent the computer from running them while still keeping the instructions visible for human readers or developers who may be reviewing the code.//
2+
//This is just an instruction for the first activity - but it is just for human consumption//
3+
//We don't want the computer to run these 2 lines - how can we solve this problem?//

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
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+
or;
7+
age += 1;

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

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

44
console.log(`I was born in ${cityOfBirth}`);
55
const cityOfBirth = "Bolton";
6+
// because we are trying to use the variable cityOfBirth before it has been declared and assigned a value.
7+
8+
//here's the corrected code://
9+
//const cityOfBirth = "Bolton";//
10+
//console.log(`I was born in ${cityOfBirth}`);//

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,12 @@ const last4Digits = cardNumber.slice(-4);
44
// The last4Digits variable should store the last 4 digits of cardNumber
55
// However, the code isn't working
66
// Before running the code, make and explain a prediction about why the code won't work
7+
// This will result in an error because the slice method is not defined for numbers. To fix this, we need to convert the cardNumber variable to a string before calling the slice method on it.
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+
//here is the corrected code://
13+
/*const cardNumber = "4533787178994213";
14+
const last4Digits = cardNumber.slice(-4);
15+
*/

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,6 @@
11
const 12HourClockTime = "8:53pm";
22
const 24hourClockTime = "20:53";
3+
// this will result in an error because variable names cannot start with a number. To fix this, we can rename the variables to start with a letter or an underscore. For this reason, we can change the variable names to something like hour12ClockTime and hour24ClockTime. This will make the variable names valid and prevent the error from occurring.
4+
//here is the corrected code://
5+
/*const hour12ClockTime = "8:53pm";
6+
const hour24ClockTime = "20:53";*/

0 commit comments

Comments
 (0)