Skip to content

Commit 633a7af

Browse files
committed
Revert Sprint-1 folder to CYF's original version
1 parent 48444ef commit 633a7af

File tree

8 files changed

+19
-128
lines changed

8 files changed

+19
-128
lines changed

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,5 @@ let count = 0;
22

33
count = count + 1;
44

5-
//
65
// Line 1 is a variable declaration, creating the count variable with an initial value of 0
7-
// Line 3 Take the current value of count, and then add 1, and store the result back in count.
6+
// Describe what line 3 is doing, in particular focus on what = is doing

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

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +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-
9-
let initials = firstName.charAt(0) + middleName.charAt(0) + lastName.charAt(0);
10-
11-
console.log(initials);
12-
8+
let initials = ``;
139

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

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

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

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

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

Lines changed: 4 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -3,74 +3,7 @@ const maximum = 100;
33

44
const num = Math.floor(Math.random() * (maximum - minimum + 1)) + minimum;
55

6-
// 1- In this exercise, you will need to work out what num represents?
7-
8-
// the num gives a random whole number between 1 and 100 like 73, 12, or 100.
9-
10-
// 2- Try breaking down the expression and using documentation to explain what it means
11-
/*
12-
13-
1. Math.random()
14-
15-
Returns a random decimal number between 0 and 1 but never gives 1.0.
16-
17-
Example: 0.24
18-
19-
2. (maximum - minimum + 1)
20-
21-
This gives number of possible values.
22-
23-
Without the +1, we'd only get the difference, not the full count.
24-
25-
for example:
26-
27-
5 - 1 = 4 → but there are actually 5 numbers: 1, 2, 3, 4, 5
28-
29-
So we add +1 to include both ends of the range.
30-
31-
3. Math.random() * (maximum - minimum + 1)
32-
33-
This gives a random decimal number between 0 and 100 (like 24, 65 ...)
34-
35-
Because we want the random decimal scaled to the size of the range of possible values.
36-
37-
For example, if we want a number between 1 and 100 (inclusive), there are 100 possible numbers (1, 2, ..., 100).
38-
39-
Multiplying by 100 means the decimal is scaled up to cover all those possibilities before rounding.
40-
41-
4. Math.floor(...)
42-
43-
This rounds the decimal down to the nearest whole number.
44-
45-
Example: Math.floor(78.43) → 78
46-
47-
5. + minimum
48-
49-
we add the minimum to shift the range correctly, and make sure the random number up to start from minimum.
50-
51-
5-1- for example if we remove the + minimum
52-
53-
5-1-1 Math.random() 0.9999 * 99 + 1 → only goes up to 99.999... → max = 99.999... → floor = 100 (but very unlikely)
54-
55-
now 100 becomes very hard to reach, and in many cases, you never get it.
56-
57-
5-1-2 Math.random() 0.00 * 99 + 1 → only goes up to 0... → max = 0... → floor = 0 (now the minimum is 0, and can appears)
58-
59-
conclusion : when we don’t add + minimum, there is a chance that 1 appears, but it’s not the guaranteed minimum anymore —
60-
61-
and the range starts at 0, not 1.
62-
63-
5-2- when we add +minimum
64-
65-
now we make sure the min and max can appear in the final results and make sure the minimum is 1 not 0.
66-
67-
Minimum appears when random = 0
68-
69-
Maximum appears when random is almost 1 (like 0.9999...).
70-
71-
example : Math.random() * 99 + 1 → up to 0.99 → max = 99 → floor = 99 → +1 = 100 (so more possibilities for 100 to appears)
72-
73-
*/
74-
75-
//It will help to think about the order in which expressions are evaluated
76-
//Try logging the value of num and running the program several times to build an idea of what the program is doing
6+
// In this exercise, you will need to work out what num represents?
7+
// Try breaking down the expression and using documentation to explain what it means
8+
// It will help to think about the order in which expressions are evaluated
9+
// Try logging the value of num and running the program several times to build an idea of what the program is doing

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

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,2 @@
1-
// we can turn the lines into comments. we can use:
2-
3-
// for single-line comments, or
4-
5-
/* for multi-line comments. */
6-
7-
/*
8-
91
This is just an instruction for the first activity - but it is just for human consumption
10-
We don't want the computer to run these 2 lines - how can we solve this problem?
11-
12-
*/
2+
We don't want the computer to run these 2 lines - how can we solve this problem?

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
// trying to create an age variable and then reassign the value by 1
2-
// Changed age declaration from const to let to allow reassignment
32

4-
let age = 33;
3+
const age = 33;
54
age = age + 1;

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// Currently trying to print the string "I was born in Bolton" but it isn't working...
2-
// what's the error ? The error here is due to using a variable before it's declared.
2+
// what's the error ?
33

44
console.log(`I was born in ${cityOfBirth}`);
55
const cityOfBirth = "Bolton";

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

Lines changed: 8 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,9 @@
1-
// We want last4Digits to store the last 4 digits of cardNumber
2-
3-
/*
4-
Prediction before running:
5-
This will cause an error because cardNumber is a number,
6-
and numbers don't have the slice() method. slice() works only on strings or arrays.
7-
8-
*/
9-
10-
/*
11-
Running the code would give:
12-
TypeError: cardNumber.slice is not a function.
13-
14-
*/
15-
16-
/*
17-
Why?
18-
Because slice() is not defined for numbers in JavaScript.
19-
20-
*/
21-
22-
/*
23-
Fix:
24-
Convert cardNumber to a string first, so we can use slice() on it.
25-
Then slice the last 4 characters to get the last 4 digits.
26-
27-
*/
28-
291
const cardNumber = 4533787178994213;
30-
31-
const last4Digits = String(cardNumber).slice(-4);
32-
33-
console.log(last4Digits); // Output: 4213
34-
2+
const last4Digits = cardNumber.slice(-4);
3+
4+
// The last4Digits variable should store the last 4 digits of cardNumber
5+
// However, the code isn't working
6+
// Before running the code, make and explain a prediction about why the code won't work
7+
// Then run the code and see what error it gives.
8+
// Consider: Why does it give this error? Is this what I predicted? If not, what's different?
9+
// Then try updating the expression last4Digits is assigned to, in order to get the correct value

0 commit comments

Comments
 (0)