-
-
Notifications
You must be signed in to change notification settings - Fork 398
West-Midlands |26-May-ITP |Maryam Janjua |Sprint 1 |Complete Sprint 1 Course Work #1409
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 6 commits
2d865ae
5e52076
9dcebe9
aef0c07
d89f407
c750fa3
9ec9ff5
9e6aff6
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,2 +1,4 @@ | ||
| 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? | ||
|
|
||
| //As age was constant there we can't change the value of age like this. I made age let so it can change the value of age. |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,9 @@ | ||
| // trying to create an age variable and then reassign the value by 1 | ||
|
|
||
| const age = 33; | ||
| let age = 33; | ||
| age = age + 1; | ||
| console.log(age); | ||
|
|
||
| /*As age was constant here we can't change the value of age like this. | ||
| because in line 4, the value of age is incremented by 1 and assigning again to age but if variable is const we can't change. | ||
| I made age let so I can change the value of age.*/ |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,13 @@ | ||
| // 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}`); | ||
|
|
||
| /* | ||
| It a reference error, we cannot access cityOfBirth before initializing it. We are trying to fetch a | ||
| value of cityOfbirth without declaring it. The interpreter first runs the line 1 i.e console.log one | ||
| and try to find a value but its not declare and it will give a error. Though we have declare is in line 2 | ||
| but js is an interpreted language that interpret line by line and runs the code. | ||
| The cityOfBirth is in locked state right now js couldn't access until reaches to it. | ||
| Right now it is in temporal locked state. | ||
| */ |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,9 +1,24 @@ | ||
| const cardNumber = 4533787178994213; | ||
| const cardNumber = "4533787178994213"; | ||
| const last4Digits = cardNumber.slice(-4); | ||
| console.log(last4Digits); | ||
|
|
||
| //const cardNumber = 4533787178994213; | ||
| //const lastdig = cardNumber.toString().slice(-4); | ||
| //console.log(lastdig); | ||
|
|
||
| // 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 | ||
|
|
||
| /* | ||
| Slice is a string method we are using it on number. | ||
| We can convert the number into string and then apply slice() method to retrieve last four digits or simply we | ||
| can declare number as a string using quotes. | ||
| Run a code : It gives TypeError and js gives this error when method/operation isn't valid for particular data | ||
| type using. | ||
| I got the idea of data type that slice() method can't use for this data type. | ||
| I attempt it by both ways I mentioned above. | ||
| */ |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,2 +1,6 @@ | ||
| const 12HourClockTime = "8:53pm"; | ||
| const 24hourClockTime = "20:53"; | ||
| const HourClockTime12 = "8:53pm"; | ||
| const hourClockTime24 = "20:53"; | ||
|
|
||
| /*The variable name cannot start with number. It can begin with _, $ or a letter. | ||
| I fixed it by renaming the variable names. | ||
| */ |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,5 @@ | ||
| const movieLength = 8784; // length of movie in seconds | ||
|
|
||
| //const movieLength = 8784; // length of movie in seconds | ||
| const movieLength = 9893; | ||
| const remainingSeconds = movieLength % 60; | ||
| const totalMinutes = (movieLength - remainingSeconds) / 60; | ||
|
|
||
|
|
@@ -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? | ||
| //six | ||
|
|
||
| // b) How many function calls are there? | ||
| // 1 i.e console.log | ||
|
|
||
| // c) Using documentation, explain what the expression movieLength % 60 represents | ||
| // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Arithmetic_Operators | ||
| // This is a reminder operator. It divides one number by another and gives a reminder. | ||
|
|
||
| // d) Interpret line 4, what does the expression assigned to totalMinutes mean? | ||
|
|
||
| /* const totalMinutes = (movieLength - remainingSeconds) / 60 | ||
| Firstly it will evaluate bracket i.e (movieLength - remainingSeconds) and then divide the value by 60. | ||
| */ | ||
| // e) What do you think the variable result represents? Can you think of a better name for this variable? | ||
|
|
||
| // The result represents the how long the movie is, in hours, minutes and seconds. It can named as MovieDuration. | ||
| // f) Try experimenting with different values of movieLength. Will this code work for all values of movieLength? Explain your answer | ||
| // Yes, I changed the value of movieLength and it worked. The movieLength is the variable used in calculating other | ||
| // values and to evaluate the total length of movie. | ||
|
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. It may work without errors, but are there any possible inputs where the output doesn't look quite right?
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. Yes, I found that although the code worked without errors, the output was not always formatted correctly. For example, when the hours, minutes, or seconds were less than 10 (e.g. 7 or 5), they were displayed as single digits instead of two digits. I fixed this by adding a helper function that adds a leading zero to single-digit values before formatting the duration. |
||
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.
Does"MovieDuration" make enough of a distinction to the other variable name called "movieLength"?
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.
Thanks for the feedback. I agree that MovieDuration was too similar to movieLength, so I've renamed it to duration to make the distinction clearer.