File tree Expand file tree Collapse file tree 7 files changed +50
-13
lines changed
Expand file tree Collapse file tree 7 files changed +50
-13
lines changed Original file line number Diff line number Diff line change 88// └──────┴──────────────┴──────┴─────┘
99
1010// (All spaces in the "" line should be ignored. They are purely for formatting.)
11-
11+ //home / user /dir / file.txt;
1212const filePath = "/Users/mitch/cyf/Module-JS1/week-1/interpret/file.txt" ;
13- const lastSlashIndex = filePath . lastIndexOf ( "/" ) ;
13+ const lastSlashIndex = filePath . lastIndexOf ( "/" ) ; //=index 47 /
1414const base = filePath . slice ( lastSlashIndex + 1 ) ;
1515console . 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
Original file line number Diff line number Diff line change @@ -2,8 +2,20 @@ const minimum = 1;
22const maximum = 100 ;
33
44const 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
Original file line number Diff line number Diff line change 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
Original file line number Diff line number Diff line change 11// trying to create an age variable and then reassign the value by 1
22
3- const age = 33 ;
3+ let age = 33 ;
44age = 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"
Original file line number Diff line number Diff line change 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+
55const cityOfBirth = "Bolton" ;
6+ console . log ( `I was born in ${ cityOfBirth } ` ) ;
7+
8+ // Error trying to use the variable "cityOfBirth"before declare it
Original file line number Diff line number Diff line change 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 ) ;
Original file line number Diff line number Diff line change 1- const 12 HourClockTime = "20:53" ;
2- const 24 hourClockTime = "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
You can’t perform that action at this time.
0 commit comments