-
-
Notifications
You must be signed in to change notification settings - Fork 333
London | 26-ITP-Jan | Boualem Larbi Djebbour | sprint 1 | Coursework #1090
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
d20c0a3
3428f41
38427c2
2f3f08d
44271ba
e0b3256
21914bb
17d93a6
af48176
4ba270e
67c8968
b72751f
35fdc82
4fdfb07
d100737
3bcd5ba
5809aee
eee4034
db44748
429f649
92bd8ef
56b74d5
5196c63
122c731
7d09f40
7b87fbc
652dbc1
bbdcc95
177c368
3bb9ddf
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 |
|---|---|---|
|
|
@@ -17,7 +17,10 @@ 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 = ; | ||
| const dir = filePath.slice(0,lastSlashIndex+1); | ||
| const ext = filePath.slice(-3); //the extention of the file is always the last three characters in the path | ||
| //or | ||
| const lastPointIndex = filePath.lastIndexOf("."); | ||
| const ext = filePath.slice(lastPointIndex+1); | ||
|
Comment on lines
+23
to
+24
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. This approach is better because it works for extensions of any length. |
||
|
|
||
| // https://www.google.com/search?q=slice+mdn | ||
| // https://www.google.com/search?q=slice+mdn | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -7,3 +7,14 @@ 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 | ||
|
|
||
| // the num represents a value with limited interval and that's why | ||
| // the num assigned to a value that's in the dor of an expression | ||
| // the math object is invoked to perform some mathematical tasks | ||
| // the random method is invoked to get a random number between 0 and 1 | ||
| // the random number is multiplied by 100 | ||
| // the floor method is invoked to round down the result to its nearest integer | ||
| // added one to the new result | ||
| // the final result of the whole expression is what the variable num assigned to | ||
| /* after applying the program several times, I got the idea that the program is generating | ||
| a value to the num variable thats always between minimum an maximum*/ | ||
|
Comment on lines
+11
to
+20
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, |
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,2 +1,3 @@ | ||
| 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? | ||
| // to make the computer not running these two line we use inline comments by adding two slashes at the beginning of each line |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,4 @@ | ||
| // trying to create an age variable and then reassign the value by 1 | ||
|
|
||
| const age = 33; | ||
| let age = 33; // we should use the keyword 'let' to declare the variable 'age' to allow reassignment later | ||
| age = age + 1; |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,7 @@ | ||
| // 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"; | ||
| console.log(`I was born in ${cityOfBirth}`); | ||
|
|
||
| // the error is that the variable 'cityOfBirth' is declared after the statement it is used in |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,9 +1,18 @@ | ||
| const cardNumber = 4533787178994213; | ||
| const last4Digits = cardNumber.slice(-4); | ||
| const last4Digits = (cardNumber.toString()).slice(-4); | ||
|
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. Dot operator is evaluated from left to right. So the parentheses around |
||
|
|
||
| // 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 | ||
|
|
||
| /* my prediction about why the code isn't working is because either the new variable is declared with const keyword | ||
| or the value of the variable cardNumber is a number not a string whereas the method .slice works only with strings */ | ||
| // the error it gives 'cardNumber.slice is not a function' | ||
| // It gives this error because the computer assumes the coder is trying to invoke a function | ||
| // yes it is my second prediction | ||
| // updating the expression last4Digits is assigned to, in order to get the correct value is as follows | ||
| // method one: puting the value of the variable cardNumber into quotes | ||
| // method two: invoking the method .toString() to convert the type of the variable from number to string | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,2 +1,6 @@ | ||
| const 12HourClockTime = "20:53"; | ||
| const 24hourClockTime = "08:53"; | ||
| const _12HourClockTime = "20:53"; // identifier can not begin with a number | ||
| // or | ||
| const $12HourClockTime = "20:53"; // or any change that makes the identifier not stating with digit | ||
| const _24hourClockTime = "08:53"; // identifier can not begin with a number | ||
| // or | ||
| const $24hourClockTime = "08:53"; // or any change that makes the identifier not stating with digit | ||
|
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. Starting a variable name with a $ is generally not recommended. Normal practice is to begin a variable name with a lowercase letter. |
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -12,14 +12,21 @@ console.log(result); | |
| // For the piece of code above, read the code and then answer the following questions | ||
|
|
||
| // a) How many variable declarations are there in this program? | ||
| // there are 6 variable declaration | ||
|
|
||
| // b) How many function calls are there? | ||
| // there is one function call (console.log()) | ||
|
|
||
| // c) Using documentation, explain what the expression movieLength % 60 represents | ||
| // it represents the remaining of dividing movielength by 60 | ||
| // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Arithmetic_Operators | ||
|
|
||
| // d) Interpret line 4, what does the expression assigned to totalMinutes mean? | ||
| // it means the integer quotient of dividing movieLength by 60 | ||
|
|
||
| // e) What do you think the variable result represents? Can you think of a better name for this variable? | ||
| // it represents the length of the movie in hours, minutes and seconds format | ||
| // a better name would be: movieTimeVolume | ||
|
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. The name Can you suggest a more descriptive name? |
||
|
|
||
| // f) Try experimenting with different values of movieLength. Will this code work for all values of movieLength? Explain your answer | ||
| // no it will not work for negative input values as it gives negative results | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -25,3 +25,8 @@ console.log(`£${pounds}.${pence}`); | |
|
|
||
| // To begin, we can start with | ||
| // 1. const penceString = "399p": initialises a string variable with the value "399p" | ||
| // line 3: calling substring method to remove the 'p' letter and keep only digits in the string | ||
| // line 8: using padstart method to make the minimum length of the string to 3 characters by adding one zero or two to the left. | ||
| // line 9: using substring method to take only the integer part | ||
| // line 14: using substring method to take only the decimal part and padend method to make the minimum length of pence to 2 characters by adding zero to the right | ||
|
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. Optional challenge: |
||
| // line 18: calling console function to print the integer part that represents the pound and the decimal part that represents the pence seprated by point | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -16,5 +16,3 @@ function square(3) { | |
| // Finally, correct the code to fix the problem | ||
|
|
||
| // =============> write your new code here | ||
|
|
||
|
|
||
|
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. There should not be modified files in the Sprint-2 folder in a PR created for Sprint-1 exercise. Can you revert (undo) the changes made in the Sprint-2 folder? |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,14 +1,26 @@ | ||
| // Predict and explain first... | ||
|
|
||
| // =============> write your prediction here | ||
| // =============> the function when called will throw an error | ||
|
|
||
| function multiply(a, b) { | ||
| console.log(a * b); | ||
| } | ||
|
|
||
| console.log(`The result of multiplying 10 and 32 is ${multiply(10, 32)}`); | ||
|
|
||
| // =============> write your explanation here | ||
| // =============> the function multiply has no return statement | ||
|
|
||
| // Finally, correct the code to fix the problem | ||
| // =============> write your new code here | ||
| // =============> | ||
| function multiply(a, b) { | ||
| return (a * b); // we change the console.log statement with the return statement | ||
| } | ||
|
|
||
| console.log(`The result of multiplying 10 and 32 is ${multiply(10, 32)}`); | ||
|
|
||
| // an extra notice: the purpose of creating a function is to reuse it when needed | ||
| // I've noticed that the parameters are already assigned to values 10 and 32, so I changed the code to the following: | ||
| function multiply(a, b) { | ||
| return console.log(`The result of multiplying ` + a +` and ` + b +` is ` + (a * b)); | ||
| } | ||
| multiply(10, 32); |
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.
Do you intend to include a trailing
/in the value assigned todir?