generated from CodeYourFuture/Module-Template
-
-
Notifications
You must be signed in to change notification settings - Fork 336
London | 26-ITP-Jan | Carlos Abreu | Sprint 1 | Coursework #1146
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
Open
carlosyabreu
wants to merge
19
commits into
CodeYourFuture:main
Choose a base branch
from
carlosyabreu:coursework/sprint-1
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
9c9c894
1-count.js committed
carlosyabreu 93a764c
2-initials.js committed
carlosyabreu 0b13c15
3-paths.js committed
carlosyabreu 96b6f9b
4-random.js committed
carlosyabreu da4cf4c
0.js committed
carlosyabreu d2f6fa0
1.js committed
carlosyabreu e6761d2
2.js committed
carlosyabreu b18653b
1.js changed const variable to let variable
carlosyabreu 8d8f9c8
Add .swp on .gitignore
carlosyabreu a21e52a
4-random.js committed
carlosyabreu 8c32fc3
Changed 'we should' for 'it should' as it makes the code more intuitive
carlosyabreu 1b7863b
2.jscommitted
carlosyabreu 250c21f
3.jscommitted
carlosyabreu 5795f10
4.js committed
carlosyabreu 3f1bc2f
1-percentage-change.js committed
carlosyabreu 81e6213
2-time-format.js committed
carlosyabreu cf82eb5
3-to-pounds.js committed
carlosyabreu 8d61f8c
chrome.md and objects.md committed
carlosyabreu 488ef4c
1-percentage-change.js committed adding a comma
carlosyabreu 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,5 @@ | ||
| node_modules | ||
| .DS_Store | ||
| .vscode | ||
| **/.DS_Store | ||
| *.swp | ||
| **/.DS_Store |
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,6 @@ | ||
| 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 // tells JavaScript to ignore everything after it on that line, so the computer will not try to execute these instructions as code, but it remains visible for humans to read and understand 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,17 @@ | ||
| /** | ||
| // trying to create an age variable and then reassign the value by 1 | ||
|
|
||
| const age = 33; | ||
| age = age + 1; | ||
| */ | ||
|
|
||
| /** | ||
| * There's a problem with your code. It's trying to reassign a value to a const variable, which is not allowed in JavaScript as const variables cannot be changed after they're declared. | ||
| * It returns a 'TypeError: Assignment to constant variable' | ||
| * To fix this, it should use let instead: | ||
| */ | ||
|
|
||
| // trying to create an age variable and then reassign the value by 1 using the keywork 'let' instead of 'const' | ||
|
|
||
| let age = 33; | ||
| age = age + 1; |
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,26 @@ | ||
| /** | ||
| * | ||
| // 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"; | ||
| */ | ||
|
|
||
| /** | ||
| * The error is that you're trying to use the variable cityOfBirth in the template literal before it has been declared and initialized. | ||
|
|
||
| In JavaScript, you cannot access a const variable before its declaration. This creates what it's callled in JavaScript a Temporal Dead Zone (TDZ) error. | ||
|
|
||
| Fix: Move the console.log statement after the variable declaration: | ||
| */ | ||
|
|
||
| // Currently trying to print the string "I was born in Bolton" but it isn't working... | ||
| // what's the error ? | ||
|
|
||
| // The error is: | ||
| // ReferenceError: Cannot access 'cityOfBirth' before initialization | ||
|
|
||
| const cityOfBirth = "Bolton"; | ||
| console.log(`I was born in ${cityOfBirth}`); | ||
|
|
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,40 @@ | ||
| /** Original 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 | ||
|
|
||
| /** Prediction | ||
| The code won't work because cardNumber is defined as a number (4533787178994213), but the .slice() method is a string method. Numbers don't have a .slice() method. | ||
| When the code runs, JavaScript will throw a TypeError saying: | ||
| cardNumber.slice is not a function | ||
| */ | ||
|
|
||
| /** | ||
| * Running: | ||
| * When running the code we get. | ||
| * TypeError: cardNumber.slice is not a function | ||
| * | ||
| * This matches prediction above that the error occurs because we're trying to use a string method on a number. | ||
| */ | ||
|
|
||
| /** | ||
| * Why the error occurs: | ||
| .slice() is a method that belongs to the String and Array prototypes, not the Number prototype. When JavaScript tries to execute cardNumber.slice(-4), it looks for a slice property on the number object, and can't find it, and throws a TypeError message. | ||
| */ | ||
|
|
||
| /** Fixing the code | ||
| To get the last 4 digits correctly, we need to convert the number to a string first then performs the operation. | ||
| */ | ||
|
|
||
| const cardNumber = 4533787178994213; | ||
| const last4Digits = cardNumber.toString().slice(-4); | ||
|
|
||
| console.log(last4Digits); // "4213" |
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,12 @@ | ||
| /** | ||
| const 12HourClockTime = "20:53"; | ||
| const 24hourClockTime = "08:53"; | ||
| const 24hourClockTime = "08:53"; | ||
| */ | ||
|
|
||
| /** | ||
| * In JavaScript, variable names cannot start with a number. They must begin with a letter, underscore (_), or dollar sign ($). | ||
| */ | ||
|
|
||
| // Here the correct version | ||
| const twelveHourClockTime = "20:53"; | ||
| const twentyFourHourClockTime = "08:53"; |
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
Oops, something went wrong.
Oops, something went wrong.
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.
Operation like
count = count + 1is very common in programming, and there is a programming term describing such operation.Can you find out what one-word programming term describes the operation on line 3?
Uh oh!
There was an error while loading. Please reload this page.
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.
Evening @cjyuan
Absolutely sure.
The operator = is called the assignment operator.
On the right hand side of =, the expression count + 1 is evaluated first.
Since count currently has the value 0, count + 1 results in 1.
Then the result 1 is assigned to the variable count on the left hand side of the operator =.
At this stage the value stored in count becomes 1.
To wrap up the line 3 does is to take the current value of count, add 1 to it, and store the result back into count.
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.
I was asking for the programming term for operation like "count = count + 1" or "count++".