Skip to content

Commit 2627edd

Browse files
committed
solution
1 parent f5b9e81 commit 2627edd

9 files changed

Lines changed: 32 additions & 15 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 reassigning the existing count variable with the existing value of count incremented by 1
Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,15 @@
1-
const firstName = "Creola";
2-
const middleName = "Katherine";
3-
const lastName = "Johnson";
1+
const firstName = 'Creola';
2+
const middleName = 'Katherine';
3+
const lastName = 'Johnson';
44

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+
var firstLetter = firstName[0];
9+
var secondLetter = middleName[0];
10+
var thirdLetter = lastName[0];
11+
12+
initials = firstLetter + secondLetter + thirdLetter;
13+
console.log(initials);
914

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

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,15 @@
99

1010
// (All spaces in the "" line should be ignored. They are purely for formatting.)
1111

12-
const filePath = "/Users/mitch/cyf/Module-JS1/week-1/interpret/file.txt";
13-
const lastSlashIndex = filePath.lastIndexOf("/");
12+
const filePath = '/Users/mitch/cyf/Module-JS1/week-1/interpret/file.txt';
13+
const lastSlashIndex = filePath.lastIndexOf('/');
1414
const base = filePath.slice(lastSlashIndex + 1);
1515
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
1919

20-
const dir = ;
21-
const ext = ;
20+
const dir = filePath.slice(0, lastSlashIndex);
21+
const ext = base.split('.')[1];
2222

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: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,11 @@ const maximum = 100;
33

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

6+
console.log(num);
7+
68
// In this exercise, you will need to work out what num represents?
79
// Try breaking down the expression and using documentation to explain what it means
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
12+
13+
// Will produce a random number above 1

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
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?

Sprint-2/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+
6+
age = 1;

Sprint-2/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...
22
// what's the error ?
33

4+
const cityOfBirth = 'Bolton';
45
console.log(`I was born in ${cityOfBirth}`);
5-
const cityOfBirth = "Bolton";

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

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,14 @@
11
const cardNumber = 4533787178994213;
2-
const last4Digits = cardNumber.slice(-4);
2+
const last4Digits = String(cardNumber).slice(-4);
33

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+
8+
// PREDICTION: won't work because slice is an arr or string method but it's being applied to a int
9+
710
// Then run the code and see what error it gives.
11+
// type error received
12+
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

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
const 12HourClockTime = "8:53pm";
2-
const 24hourClockTime = "20:53";
1+
const twelveHourClockTime = '8:53pm';
2+
const twentyFourHourClockTime = '20:53';

0 commit comments

Comments
 (0)