-
-
Notifications
You must be signed in to change notification settings - Fork 239
Manchester | 25-ITP-Sep | Hani Sadah| Sprint 1 | Coursework/sprint 1 #810
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
af8a542
e4c2e57
b21591e
4102ecb
8f90b4f
1da375f
beda7c4
e7f48d3
a661310
f4e13bc
b6b4ffc
2478f22
8beb07d
f070a00
ad0f006
e082897
85bcc9b
491f9b8
c5a8edb
b0547d6
9b194a5
75b0d32
6b1aed0
883efa2
4ca75b9
e4ba658
c57d664
9bf4964
d868527
9b9dc8e
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,24 @@ | ||
| // 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.) | ||
|
|
||
|
|
||
| // 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}`); | ||
| const base = filePath.slice(lastSlashIndex + 1); // file.txt | ||
| 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 | ||
| // 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 = ; | ||
| const dir = filePath.slice(0, lastSlashIndex) | ||
| const ext = filePath.slice(filePath.lastIndexOf(".")); | ||
|
|
||
| console.log (dir, ext) | ||
| // https://www.google.com/search?q=slice+mdn |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -7,3 +7,15 @@ const num = Math.floor(Math.random() * (maximum - minimum + 1)) + minimum; | |
| // Try breaking down the expression and using documentation to explain what it means | ||
| // It will help to think about the order in which expressions are evaluated | ||
| // Try logging the value of num and running the program several times to build an idea of what the program is doing | ||
|
|
||
| //num represents the results of equations at the right side of operator = | ||
|
|
||
| //step-1---> Math.random() generates a random decimal. | ||
| //step-2---> (maximum - minimum + 1) evaluates to 100. | ||
| //step-3---> Math.random() is multiplied by (maximum - minimum + 1) which is 100, resulting in a random decimal between 0 and 100. | ||
|
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. Phrases like "a number between X and Y" are not precise enough in a program specification, because they do not clearly state whether the endpoints X and Y are included. We can also use the concise and precise interval notation to describe a range of values.
For example, we can describe a number, Can you use this notation to describe the return value of |
||
| //step-4---> the result of Step-3 is round by the method Math.floor. | ||
| //step-5---> minimum is added to the result of step-4. | ||
| //Therefore, num represents random numbers generated between minimum 1 and maximum 100, as we run the code several times | ||
| //generates new numbers. | ||
|
|
||
| console.log(num); | ||
| 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,7 @@ | ||
| // trying to create an age variable and then reassign the value by 1 | ||
|
|
||
| const age = 33; | ||
| // in this case, we will need to replace the const keyword with let keyword as const vasriable refuses to be reassigned. | ||
| let age = 33; | ||
| age = age + 1; | ||
|
|
||
| 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}`); | ||
| // we need to declare the variable cityOfBirth first then we can print it out. | ||
| const cityOfBirth = "Bolton"; | ||
| console.log(`I was born in ${cityOfBirth}`); |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,9 +1,15 @@ | ||
| const cardNumber = 4533787178994213; | ||
| const last4Digits = cardNumber.slice(-4); | ||
| const last4Digits = cardNumber.toString().slice(-4); | ||
| console.log (last4Digits); | ||
|
|
||
| // 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 | ||
|
|
||
| // it seems that the code is not working because the cardNumber variable is not defined as a string. | ||
| // my prediction is true. | ||
|
|
||
| //we need to add string to the variable cardNumber variable before using the slice method then to print the code out. |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,2 +1,16 @@ | ||
| const 12HourClockTime = "20:53"; | ||
| const 24hourClockTime = "08:53"; | ||
| const 24hourClockTime = "08:53"; | ||
|
|
||
| // we have to convert the identifiers of the variables to valid ones by removing the 12 and 24 digits and to put them in camel case format. | ||
| const twelveHourClockTime = "20:53"; | ||
| const twentyFourHourClockTime = "08:53"; | ||
|
|
||
| console.log(twelveHourClockTime); | ||
| console.log(twentyFourHourClockTime); | ||
|
|
||
| // The twelveHourClockTime and twentyFourHourClockTime variables should store the respective time formats | ||
| // 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 variable names to valid identifiers in order to get the correct value |
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.
I was referring to the operation that increase the value of a variable by 1. For example,
count = count + 1.Can you look up the name of such operation?