-
-
Notifications
You must be signed in to change notification settings - Fork 386
London | 26-ITP-JAN | Shuheda Begum | Sprint 1 | Structuring and Testing Data #937
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
Changes from 16 commits
c82ecac
13c3a8a
3dae4d0
f4adea0
9f0fe23
7d2f848
9c2b2fc
c557dca
704d372
3d0ea75
c611ae5
978fdbf
22aca43
499906a
6cb823c
2fd76d2
4c474e3
4a41676
2e95c35
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? | ||
| // The forward slash is used to indicate a comment in JavaScript, so the computer will ignore these lines when running the program. |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,8 @@ | ||
| // 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); | ||
|
|
||
| // The code above will output 34, because we are reassigning the value of age to be the current value of age plus 1. So, 33 + 1 = 34. | ||
|
|
||
| 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 happens because cityOfBirth is used before it is defined. JavaScript runs code from top to bottom, so the variable must be declared first. |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,9 +1,12 @@ | ||
| const cardNumber = 4533787178994213; | ||
| const last4Digits = cardNumber.slice(-4); | ||
| const last4Digits = String(cardNumber).slice(-4); | ||
|
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. Now, you did the right thing by explaining your reasoning to debug the error. I would suggest applying a much cleaner way to convert the variable into a string without redeclaring it. You can look into that method using MDN docs.
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. Ok, thank you. |
||
| console.log(last4Digits); //"4213" | ||
|
|
||
| // 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 didn’t work because slice() is a string method, not a number method, so the card number must be converted to a string first. | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,2 +1,11 @@ | ||
| const 12HourClockTime = "20:53"; | ||
| const 24hourClockTime = "08:53"; | ||
| // const 12HourClockTime = "20:53"; | ||
| // const 24hourClockTime = "08:53"; | ||
|
|
||
| // Variables cannot start with a number. | ||
| // When JavaScript tries to run the code, it throws a SyntaxError. | ||
| // To fix the error we can rename the variable to start with a letter, a underescore_ or a dollar sign $ instead of a number. | ||
|
|
||
| const twelveHourClockTime = "8:53"; | ||
| const twentyFourHourClockTime = "08:53"; | ||
|
|
||
| // I changed the time to match the 12 and 24 hr clock format. |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -13,13 +13,41 @@ console.log(result); | |
|
|
||
| // a) How many variable declarations are there in this program? | ||
|
|
||
| // There are 6 variable declarations in this program. They are on lines 1, 3, 5, 7, 9 and 11. The variables being declared are movieLength, remainingSeconds, totalMinutes, remainingMinutes, totalHours and result. | ||
|
|
||
|
|
||
|
|
||
| // b) How many function calls are there? | ||
|
|
||
| // There is 1 function calls in this program. It is on lines 10. The functions is the 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 | ||
|
|
||
| // % is the remainder operator. | ||
| // movieLength % 60 - This gives the remainder when movieLength is divided by 60. | ||
| // Since there are 60 seconds in a minute, this tells us how many leftover seconds there are after counting full minutes. | ||
| // For example, 8784 % 60 = 24. So there are 24 seconds left after counting the minutes. | ||
|
|
||
|
|
||
|
|
||
| // d) Interpret line 4, what does the expression assigned to totalMinutes mean? | ||
|
|
||
| // movieLength - remainingSecond - This gives the total number of seconds in the movie after removing the leftover seconds. | ||
| // Divide by 60 - this converst the seconds into total full minutes. eg. (8784 - 24) = 8760, 8760 / 60 = 146. | ||
|
|
||
|
|
||
|
|
||
| // e) What do you think the variable result represents? Can you think of a better name for this variable? | ||
|
|
||
| // The variable result is a string that represents the movie length in hours:minutes:seconds | ||
| // For example: 2:26:24 (2 hours, 26 minutes, 24 seconds) | ||
| // Better name can be movieDurationString. | ||
|
|
||
|
|
||
|
|
||
| // f) Try experimenting with different values of movieLength. Will this code work for all values of movieLength? Explain your answer | ||
|
|
||
| // This code will work for all positive integer values of movieLength. It will correctly calculate the hours, minutes and seconds for any length of movie. However, if movieLength is negative or not an integer, the code may not work as intended. For example, if movieLength is -100, the calculations will not make sense in the context of a movie length. If movieLength is a decimal, it may also cause issues with the calculations. | ||
|
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. Have you considered if there could be some time formatting issues with smaller integer numbers?
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 didn't think of that. I will have a look at this now. |
||
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 think the explanation provided here hit the major reason why the error was occurring even if you did the right thing in your code?
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.
No. I have now included this . Thank you.