Skip to content

Commit e9af9ad

Browse files
committed
charAt()
slice() Math.floor() Math.random() lastIndexOf() replaceAll()
1 parent 6732232 commit e9af9ad

File tree

7 files changed

+50
-13
lines changed

7 files changed

+50
-13
lines changed

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

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,20 +8,22 @@
88
// └──────┴──────────────┴──────┴─────┘
99

1010
// (All spaces in the "" line should be ignored. They are purely for formatting.)
11-
11+
//home / user /dir / file.txt;
1212
const filePath = "/Users/mitch/cyf/Module-JS1/week-1/interpret/file.txt";
13-
const lastSlashIndex = filePath.lastIndexOf("/");
13+
const lastSlashIndex = filePath.lastIndexOf("/"); //=index 47 /
1414
const base = filePath.slice(lastSlashIndex + 1);
1515
console.log(`The base part of ${filePath} is ${base}`);
1616

1717

1818

1919
// Create a variable to store the dir part of the filePath variable
20-
const dir = filePath.slice(1,5);
21-
console.log(dir);
20+
const dir = filePath.slice(0, lastSlashIndex + 1);
21+
console.log(`The directory part is: ${dir}`);
2222

2323
// Create a variable to store the ext part of the variable
24-
24+
const lastDotIndex = filePath.lastIndexOf("."); // look for the last Dot
25+
const extPart = filePath.slice(lastDotIndex + 1);
26+
console.log(`The extension part is: ${extPart}`);
2527

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

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

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,20 @@ const minimum = 1;
22
const maximum = 100;
33

44
const num = Math.floor(Math.random() * (maximum - minimum + 1)) + minimum;
5+
console.log(num);
56

67
// In this exercise, you will need to work out what num represents?
8+
9+
//Num represents a random number between 1 to 100 inclde both becasue we are adding 1
10+
711
// Try breaking down the expression and using documentation to explain what it means
12+
13+
//(maximum - minimum + 1) = get maximum number 100 extract the minimum 1 add +1 to incluide 100.
14+
//+ minimum add 1
15+
16+
//math.radom = gets randm number between 0 and 1 but never 1 so we add +1 to incluide 1
17+
//Math.floor= will raounds donw to the nearest whole number
18+
19+
820
// It will help to think about the order in which expressions are evaluated
921
// 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: 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+
//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?
3+
//coment the lines

Sprint-1/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+
console.log (age);
6+
7+
// error if we intend to change the value assing to a variable we need to use "LET"

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
// Currently trying to print the string "I was born in Bolton" but it isn't working...
22
// what's the error ?
33

4-
console.log(`I was born in ${cityOfBirth}`);
4+
55
const cityOfBirth = "Bolton";
6+
console.log(`I was born in ${cityOfBirth}`);
7+
8+
// Error trying to use the variable "cityOfBirth"before declare it

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

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,18 @@
1-
const cardNumber = 4533787178994213;
2-
const last4Digits = cardNumber.slice(-4);
1+
//const cardNumber = 4533787178994213;
2+
//const last4Digits = 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
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+
11+
12+
// it will not work becase Slice is a string methodo.
13+
// To work here need to convert the number to string
14+
15+
const cardNumber = 4533787178994213;
16+
const last4Digits = cardNumber.toString().slice(-4);
17+
18+
console.log(last4Digits);

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

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,9 @@
1-
const 12HourClockTime = "20:53";
2-
const 24hourClockTime = "08:53";
1+
// const 12HourClockTime = "20:53";
2+
// const 24hourClockTime = "08:53";
3+
4+
const hour12ClockTime = "20:53";
5+
const hour24ClockTime = "08:53";
6+
7+
console.log(hour12ClockTime,hour24ClockTime);
8+
9+
// variable names can't start with nunmbers

0 commit comments

Comments
 (0)