-
-
Notifications
You must be signed in to change notification settings - Fork 546
London | 26-ITP-Sept | Maharit Belai | Sprint 2 | Course work #1549
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
05c3d45
a4bfc54
686ac69
f44d3e1
f5f7707
e1dda9e
02ff8cf
6f81459
26b0b8b
3e10e6d
9a94c44
0bd5e8c
1a1c60a
4d06615
4aa68ab
2d26b97
532b0fa
f91783b
118a824
41c8775
726810c
ceffa2d
8b2dbc2
c52de96
4072533
b20c858
56bebf5
b584bde
e63d651
6b3c6ec
118d7c2
3daf70a
bd744ff
27f9052
36dd0c6
2582f53
5da1022
8211642
3ab1fb2
5a7447d
ca1cf85
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,23 +1,11 @@ | ||
| // The diagram below shows the different names for parts of a file path on a Unix operating system | ||
|
|
||
| // ┌─────────────────────┬────────────┐ | ||
| // │ dir │ base │ | ||
| // ├──────┬ ├──────┬─────┤ | ||
| // │ root │ │ name │ ext │ | ||
| // " / home/user/dir / file .txt " | ||
| // └──────┴──────────────┴──────┴─────┘ | ||
|
|
||
| // (All spaces in the "" line should be ignored. They are purely for formatting.) | ||
|
|
||
| const filePath = "/Users/mitch/cyf/Module-JS1/week-1/interpret/file.txt"; | ||
| const lastSlashIndex = filePath.lastIndexOf("/"); | ||
| const base = filePath.slice(lastSlashIndex + 1); | ||
| console.log(`The base part of ${filePath} is ${base}`); | ||
|
|
||
| // Create a variable to store the dir part of the filePath variable | ||
| // Create a variable to store the ext part of the variable | ||
|
|
||
| const dir = ; | ||
| const ext = ; | ||
|
|
||
| // https://www.google.com/search?q=slice+mdn | ||
| const startDirIndex = filePath.lastIndexOf("/Users"); | ||
| const dir = filePath.slice(startDirIndex, lastSlashIndex); | ||
| console.log(`The dir part of ${filePath} is ${dir}`); | ||
| const dotIndex = filePath.lastIndexOf("."); | ||
| const ext = filePath.slice(dotIndex); | ||
| console.log(`The ext part of the ${filePath} is ${ext}`); | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,2 +1,2 @@ | ||
| This is just an instruction for the first activity - but it is just for human consumption | ||
| We don't want the computer to run these 2 lines - how can we solve this problem? | ||
| //This is just an instruction for the first activity - but it is just for human consumption | ||
| //We don't want the computer to run these 2 lines - how can we solve this problem? |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,6 @@ | ||
| // trying to create an age variable and then reassign the value by 1 | ||
|
|
||
| const age = 33; | ||
| let age = 33; | ||
| age = age + 1; | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Your explanation on line 5 is right. Run the file though. It still stops with the same error, because line 3 is still
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done! Thank you. |
||
| // you can not reassign a value to variable that is declared const. | ||
| console.log(age); | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,6 @@ | ||
| // Currently trying to print the string "I was born in Bolton" but it isn't working... | ||
| // what's the error ? | ||
|
|
||
| console.log(`I was born in ${cityOfBirth}`); | ||
| const cityOfBirth = "Bolton"; | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Your explanation on line 6 is right. This file still stops when you run it though. What would you move, so that line 4 prints "I was born in Bolton"? |
||
| // The error is that the const declation and initialization came after console.log so no access for cityOfBirth. | ||
| console.log(`I was born in ${cityOfBirth}`); | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,9 +1,6 @@ | ||
| const cardNumber = 4533787178994213; | ||
| const cardNumber = "4533787178994213"; | ||
| const last4Digits = cardNumber.slice(-4); | ||
|
|
||
| // The last4Digits variable should store the last 4 digits of cardNumber | ||
| // However, the code isn't working | ||
| // Before running the code, make and explain a prediction about why the code won't work | ||
| // Then run the code and see what error it gives. | ||
| // Consider: Why does it give this error? Is this what I predicted? If not, what's different? | ||
| // Then try updating the expression last4Digits is assigned to, in order to get the correct value | ||
| // the code is not working because the number initialized should be in "" . | ||
| // so it can know it/or treat it as a string. | ||
| console.log(last4Digits); |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,2 +1,6 @@ | ||
| const 12HourClockTime = "8:53pm"; | ||
| const 24hourClockTime = "20:53"; | ||
| const HourClockTime = "8:53pm"; | ||
| const hourClockTime = "20:53pm"; | ||
|
|
||
| // The error here is that the variable started with number. | ||
| console.log(HourClockTime); | ||
| console.log(hourClockTime); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Run this file and look at the dir line. It prints
Users/mitch/...but the path starts with a/, so one character is missing. Two things to think about. Which index doeslastIndexOf("Users")give you? And what happens to this code if the path does not contain the wordUsersat all? Yourexton lines 9 and 10 is a good example of the approach that would work here.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My first thought was that on the image "/ " was under the root and the dir starts from "home".
so, that is why I considered dropping the "/". But now I have fixed it.