File tree Expand file tree Collapse file tree 2 files changed +30
-6
lines changed
Expand file tree Collapse file tree 2 files changed +30
-6
lines changed Original file line number Diff line number Diff line change 1010// (All spaces in the "" line should be ignored. They are purely for formatting.)
1111
1212const filePath = "/Users/mitch/cyf/Module-JS1/week-1/interpret/file.txt" ;
13+
14+ // Find the last slash and we can seperate the base from "dir"
1315const lastSlashIndex = filePath . lastIndexOf ( "/" ) ;
1416const base = filePath . slice ( lastSlashIndex + 1 ) ;
15- console . log ( `The base part of ${ filePath } is ${ base } ` ) ;
1617
17- // Create a variable to store the dir part of the filePath variable
18- // Create a variable to store the ext part of the variable
18+ // Find the last dot
19+ const lastDot = base . lastIndexOf ( "." ) ;
20+ // console.log(`The base part of ${filePath} is ${base}`);
21+
22+ // Ectract everything before the base
23+ const dir = filePath . slice ( 0 , lastSlashIndex ) ;
24+ // Extract the txt extention from the dot
25+ const ext = base . slice ( lastDot ) ;
26+
27+
28+
1929
20- const dir = ;
21- const ext = ;
2230
23- // https://www.google.com/search?q=slice+mdn
31+
32+
33+
34+
35+
36+ // Create a variable to store the dir part of the filePath variable
37+ // Create a variable to store the ext part of the variable
38+ console . log ( `The base part of ${ filePath } is ${ base } ` ) ;
39+ // Moved to bottom its confusing me
Original file line number Diff line number Diff line change @@ -7,3 +7,11 @@ const num = Math.floor(Math.random() * (maximum - minimum + 1)) + minimum;
77// Try breaking down the expression and using documentation to explain what it means
88// It will help to think about the order in which expressions are evaluated
99// Try logging the value of num and running the program several times to build an idea of what the program is doing
10+
11+ // Answer: Inermost brackets first (maximum - minimum + 1) this is calcuating the range
12+ // Math.random generated a number between 0 and 1 but wont get to 1
13+ // Math.random * 100 moved the comma by 2 decimal places
14+ // Math.floor wii remove decimal parts of the number
15+ // + minimum will add 1
16+
17+ console . log ( num ) ;
You can’t perform that action at this time.
0 commit comments