-
-
Notifications
You must be signed in to change notification settings - Fork 240
Glasgow | 25-ITP-SEP | Alaa Tagi | Sprint 1 | coursework/sprint-1 #723
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
57564ec
defadad
ac6b0e4
637cf89
ca4da7c
4793b3d
0e312da
709bed6
72a2ea2
dd95e03
5ae96f4
774c424
771dc70
84d6822
fb13fb7
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,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? | ||
| */ |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,5 @@ | ||
| // trying to create an age variable and then reassign the value by 1 | ||
|
|
||
| const age = 33; | ||
| age = age + 1; | ||
| let age = 30; // Change const to let to allow reassignment | ||
| age += 1; // Increment age by 1 | ||
| console.log(age); |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,9 +1,24 @@ | ||
| /* The old code: | ||
| 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 | ||
|
|
||
| /* My prediction: The code will give an error because the minus sign(-4) and slice works only with strings, not numbers. | ||
|
|
||
| Consideration: The error is a TypeError: cardNumber.slice is not a function. mostly it was because I predicted that numbers do not have a slice method. About the minus sign, I have learned about positive and negative indexing in strings, now I can see the difference. | ||
|
|
||
|
|
||
| To fix this, we need to convert cardNumber to a string before calling the slice method. | ||
| */ | ||
|
|
||
| // Updated code: | ||
| const cardNumber = 4533787178994213; | ||
| const last4DigitsCorrected = cardNumber.toString().slice(-4); | ||
| console.log(last4DigitsCorrected); |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,2 +1,13 @@ | ||
| /* | ||
| The old code: | ||
| const 12HourClockTime = "20:53"; | ||
| const 24hourClockTime = "08:53"; | ||
| const 24hourClockTime = "08:53"; | ||
| console.log(24hourClockTime);*/ | ||
|
|
||
| // It is giving a syntax error | ||
| // The reason is that variable names cannot start with a number | ||
|
|
||
| // Updated code: | ||
| const hourClockTime12 = "20:53"; | ||
| const hourClockTime24 = "08:53"; | ||
| console.log(hourClockTime24, hourClockTime12); |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -12,14 +12,52 @@ 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 declarations: | ||
| 1.Line 1 : const movieLength. | ||
| 2.Line 3 : const remainingSeconds. | ||
| 3.Line 4 : const totalMinutes. | ||
| 4.Line 6 : const remainingMinutes. | ||
| 5.Line 7 : const totalHours. | ||
| 6.Line 9 : const result. | ||
| */ | ||
|
|
||
| // b) How many function calls are there? | ||
|
|
||
| /* There is one function call: | ||
| Line 10 : console.log(). | ||
| */ | ||
|
|
||
| // c) Using documentation, explain what the expression movieLength % 60 represents | ||
|
|
||
| /* The movieLength represents the length of the movie in seconds, the operand % is remaining (Modulo) returns the remaining of the movieLength divided by 60(to convert sec into minutes) but it only gives the remaining of this operation. | ||
| */ | ||
|
|
||
| // 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? | ||
|
|
||
| /* | ||
| The expression assigned to completed total minutes of the movie, by subtract the movie length in sec from the remaining seconds and divide the result by 60 to convert it to minutes | ||
| */ | ||
|
|
||
| // e) What do you think the variable result represents? Can you think of a better name for this variable? | ||
|
|
||
| /* | ||
| The variable result display the total length of the movie in these form (Hours:Minutes:seconds) in string format. | ||
|
|
||
| I can think of "MovieDuration" as a better name because it gives more description to the output. | ||
|
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. Is it clear what the difference is between movieDuration and movieLength? Could I understand the difference by quickly reading these two variable names?
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. @LonMcGregor
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. @LonMcGregor what about (totalscreentime) ? is this more obvious ? 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. @Alaa-Tagi They both show the total screen time. Think of what the difference is between the movie length variable and this new variable at the end of the code (what type of data is used, what content the data holds). What different type of data is stored there? How could you make it obvious what the difference is?
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. Oh, I got what you meant now. Are you saying that the difference in datatype and representation for movie length is numeric data, while screen time is considered structured data? Is that correct? What about total_runtime_minutes? 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, that's what I was thinking. Because your final argument is formatted to show hours, minutes, seconds, rather than total seconds as an integer, picking a name that makes that clear is better. It shows the runtime with more details than just minutes, so is there an even better name?
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. I guess it can be ( runtime_hms) Is it still not better name? 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. runtime_hms sounds good to me - this makes it clear that it contains all of hours, minutes and seconds. |
||
| */ | ||
|
|
||
| // f) Try experimenting with different values of movieLength. Will this code work for all values of movieLength? Explain your answer | ||
|
|
||
| /* | ||
| I did experimenting the code by putting different value to the movieLength and it works just fine. | ||
|
|
||
| test numbers and its outcomes: | ||
| 1. 36000sec>> 10:0:0 | ||
| 2. 120 sec >> 0:2:0 | ||
| 3. 0 sec >> 0:0:0 | ||
| 4. 555555.55sec >> 154:19:15.550000000046566 | ||
|
|
||
| As the results show the code is working fine even with unexpected large numbers. | ||
| */ | ||
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.
These are correct - are they any other variables being declared?
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.
@LonMcGregor , priceDifference and precentageChange are also variables.