generated from CodeYourFuture/Module-Template
-
-
Notifications
You must be signed in to change notification settings - Fork 330
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
Closed
Closed
Changes from all commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
c82ecac
Did 1-count.js
codebyshay 13c3a8a
Testing commit via terminal
codebyshay 3dae4d0
testing reversal
codebyshay f4adea0
Update 2-initials.js
codebyshay 9f0fe23
Update 3-paths.js
codebyshay 7d2f848
Update 4-random.js
codebyshay 9c2b2fc
Update 0.js
codebyshay c557dca
const to let
codebyshay 704d372
Console and const
codebyshay 3d0ea75
Update 3.js
codebyshay c611ae5
Update 4.js
codebyshay 978fdbf
Update 1-percentage-change.js
codebyshay 22aca43
Update 2-time-format.js
codebyshay 499906a
Update 3-to-pounds.js
codebyshay 6cb823c
Update chrome.md
codebyshay 2fd76d2
Update objects.md
codebyshay 4c474e3
update error
codebyshay 4a41676
Cleaner code
codebyshay 2e95c35
Update 2-time-format.js
codebyshay File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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. | ||
| // The error in the code is that it was trying to reassign a value to a variable that was declared with let. This is not allowed in JavaScript. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,9 +1,16 @@ | ||
| const cardNumber = 4533787178994213; | ||
| const last4Digits = cardNumber.slice(-4); | ||
| //const cardNumber = 4533787178994213; | ||
| //const last4Digits = String(cardNumber).slice(-4); | ||
| //console.log(last4Digits); //"4213" | ||
|
|
||
| // Cleaner code: | ||
| const last4Digits = cardNumber.toString().slice(-4); | ||
| 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. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,25 +1,69 @@ | ||
| const movieLength = 8784; // length of movie in seconds | ||
| //const movieLength = 8784; // length of movie in seconds | ||
|
|
||
| const remainingSeconds = movieLength % 60; | ||
| const totalMinutes = (movieLength - remainingSeconds) / 60; | ||
| //const remainingSeconds = movieLength % 60; | ||
| //const totalMinutes = (movieLength - remainingSeconds) / 60; | ||
|
|
||
| const remainingMinutes = totalMinutes % 60; | ||
| const totalHours = (totalMinutes - remainingMinutes) / 60; | ||
| //const remainingMinutes = totalMinutes % 60; | ||
| //const totalHours = (totalMinutes - remainingMinutes) / 60; | ||
|
|
||
| const result = `${totalHours}:${remainingMinutes}:${remainingSeconds}`; | ||
| console.log(result); | ||
| //const result = `${totalHours}:${remainingMinutes}:${remainingSeconds}`; | ||
| //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 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. | ||
|
|
||
| const movieLength = 65; | ||
|
|
||
| const remainingSeconds = movieLength % 60; | ||
| const totalMinutes = (movieLength - remainingSeconds) / 60; | ||
|
|
||
| const remainingMinutes = totalMinutes % 60; | ||
| const totalHours = (totalMinutes - remainingMinutes) / 60; | ||
|
|
||
| const formattedHours = String(totalHours).padStart(2, "0"); | ||
| const formattedMinutes = String(remainingMinutes).padStart(2, "0"); | ||
| const formattedSeconds = String(remainingSeconds).padStart(2, "0"); | ||
|
|
||
| const movieDurationString = `${formattedHours}:${formattedMinutes}:${formattedSeconds}`; | ||
|
|
||
| console.log(movieDurationString); // 00:01:05 | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
While I understand you might have misinterpreted my comment, the point I made was not for an explicit change of the code to work with a certain range of numbers. The rationale, as seen in the task, is to explain your rationale for your answer as to how various values will work when passed into the movieLength variable.