-
-
Notifications
You must be signed in to change notification settings - Fork 546
Manchester | 26-ITP-Sep | Rahana Suleiman | Sprint 2 | Complete Sprint 2 Coursework #1563
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
rahanasuleiman8-ship-it
wants to merge
26
commits into
CodeYourFuture:main
Choose a base branch
from
rahanasuleiman8-ship-it:coursework/sprint-2
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
26 commits
Select commit
Hold shift + click to select a range
f2e91c5
complete prep folder exercises
rahanasuleiman8-ship-it 94e0982
Added description for what line 3 is doing, focusing more on what = does
rahanasuleiman8-ship-it 0cad20d
declared a variable to store first characters of each string without …
rahanasuleiman8-ship-it 14ba89d
create a variable to store both dir(filePath) and ext part of the var…
rahanasuleiman8-ship-it aeabc99
Add step-by-step explanation of Math.random, Math.floor, maximum, min…
rahanasuleiman8-ship-it 814abb5
comment out what I don't want the computer to run
rahanasuleiman8-ship-it dc97183
change age variable declaration from 'const' to 'let' to allow reassi…
rahanasuleiman8-ship-it 8ada20c
declare 'cityOfBirth' before 'console.log' to in 2.js to fix Referenc…
rahanasuleiman8-ship-it 936de83
predict and explain the error in the code, and update the expression …
rahanasuleiman8-ship-it 55fa5e7
predict and explain the error in the code, and update the expression …
rahanasuleiman8-ship-it 2fc4870
Rename variables to match JavaScript naming conventions and verify co…
rahanasuleiman8-ship-it 4922e00
-add missing comma between arguments in replaceAll() on line 5
rahanasuleiman8-ship-it bb34ab4
- verify variable declaration and function call count
rahanasuleiman8-ship-it 23673ee
Fix: update in 3-paths.js
rahanasuleiman8-ship-it 5f58ebd
Update commit
rahanasuleiman8-ship-it e8de7c3
- Add detailed explanation for substring, padStart, and padEnd methods
rahanasuleiman8-ship-it 4f6289b
remove untracked githooks file from PR
rahanasuleiman8-ship-it 88beb1f
remove prep directory files from Sprint 2 PR
rahanasuleiman8-ship-it 2b99e8c
Enhance comments for clarity on random number generation logic
rahanasuleiman8-ship-it 50075e2
Refine comments for clarity on random number generation logic
rahanasuleiman8-ship-it 097fe3e
Fix cardNumber type for correct slicing of last 4 digits
rahanasuleiman8-ship-it f5658c8
Rename variables for clarity: update HourClockTime to twelveHourClock…
rahanasuleiman8-ship-it fd72b0f
Refine comments for clarity on totalMinutes calculation and improve e…
rahanasuleiman8-ship-it 7b042b7
Refine comments for clarity and consistency in the price conversion l…
rahanasuleiman8-ship-it ca07b89
Refine comments for clarity and detail in random number generation logic
rahanasuleiman8-ship-it a11d682
Refine explanation in random number generation logic for clarity and …
rahanasuleiman8-ship-it 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,9 +1,31 @@ | ||
| const minimum = 1; | ||
| const maximum = 100; | ||
|
|
||
| const num = Math.floor(Math.random() * (maximum - minimum + 1)) + minimum; | ||
| const minimum = 1; // Sets the lowest possible number that can be generated | ||
| const maximum = 100; // Sets the highest possible number that can be generated | ||
|
|
||
| // In this exercise, you will need to work out what num represents? | ||
| // Try breaking down the expression and using documentation to explain what it means | ||
| // It will help to think about the order in which expressions are evaluated | ||
|
|
||
| const num = Math.floor(Math.random() * (maximum - minimum + 1)) + minimum; | ||
|
|
||
| /* | ||
| EXPLANATION IN ORDER OF EXECUTION (OPERATOR PRECEDENCE): | ||
|
|
||
| 1. (maximum - minimum + 1) — Grouping Parentheses (Highest Precedence): | ||
| Calculates the total number of possible whole values between minimum and maximum, inclusive (e.g., 100 - 1 + 1 = 100 possible values). | ||
|
|
||
| 2. Math.random() — Function Call: | ||
| Generates a random floating-point decimal from 0 up to (but not including) 1. | ||
|
|
||
| 3. Math.random() * (maximum - minimum + 1) — Multiplication: | ||
| calculates the total number of possible values between minimum and maximum, (but not including) 100 (e.g., 0 to 99.999...). | ||
|
|
||
| 4. Math.floor(...) — Function Call: | ||
| Rounds the decimal down to the nearest whole integer, converting the range from [0, 99.999...] to an integer from 0 to 99. | ||
|
|
||
| 5. + minimum — Addition (Lowest Precedence): | ||
| Shifts the whole set of numbers up so that the lowest outcome becomes `minimum` (1) instead of 0, resulting in a whole number between 1 and 100 inclusive. | ||
| */ | ||
|
|
||
| // Try logging the value of num and running the program several times to build an idea of what the program is doing | ||
|
|
||
| console.log(num); // num represents a random whole number between 1 and 100 inclusive | ||
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,7 @@ | ||
| 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?*/ | ||
|
|
||
|
|
||
| //ANSWER: | ||
|
|
||
| // We comment them out |
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,11 @@ | ||
| // trying to create an age variable and then reassign the value by 1 | ||
|
|
||
| const age = 33; | ||
| // The problem here is that 'const' creates a constant variable which cannot be reassigned, attempting to reassign (age = age + 1) throws a TypeError: Assignment to constant variable. | ||
|
|
||
|
|
||
| //change 'const' to 'let' so the value can be updated | ||
| // const age = 33; | ||
| let age = 33; | ||
| age = age + 1; | ||
|
|
||
| // console.log(age); |
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,12 @@ | ||
| // 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}`); | ||
| // The error is a ReferenceError: Cannot access 'cityOfBirth' before initialization | ||
| // In JavaScript variables declared with 'const' or 'let' cannot be accessed before they are declared or initialized | ||
|
|
||
|
|
||
| //SOLUTION | ||
| // move the variable declaration above the 'console.log()' | ||
| 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,22 @@ | ||
| 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 | ||
|
|
||
| //Prediction: The code won't work because cardNumber is stored as a Number and not a string, this is because '.slice()' is a string method | ||
| // Numbers in JavaScript don't work with '.slice()' | ||
|
|
||
|
|
||
| // Then run the code and see what error it gives. | ||
| //This is the error it gives: TypeError: cardNumber.slice is not a function | ||
|
|
||
|
|
||
| // Consider: Why does it give this error? Is this what I predicted? If not, what's different? | ||
|
|
||
| //Explanation: Yes, my prediction was accurate. JavaScript threw a TypeError because '.slice()' is a string method | ||
| // Then try updating the expression last4Digits is assigned to, in order to get the correct value | ||
| // Keep the original number value untouched | ||
| const cardNumber = 4533787178994213; | ||
| // Convert to string dynamically before slicing | ||
| const last4Digits = cardNumber.toString().slice(-4); | ||
|
|
||
| console.log(last4Digits); // output 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,7 @@ | ||
| const 12HourClockTime = "8:53pm"; | ||
| const 24hourClockTime = "20:53"; | ||
| // JavaScript variable names cannot start with a number. They must start with an alphabet(A-Z), an underscore(_), or a dollar sign($). JavaScript is also case sensitive so they have to use camelCase, PascalCase, among others. | ||
|
|
||
| const twelveHourClockTime = "8:53pm"; | ||
| const twentyFourHourClockTime = "20:53"; | ||
|
|
||
| // console.log(HourClockTime); | ||
| // console.log(hourClockTime); |
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
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.
Good explanation overall, but Math.floor() doesn't round up, please review the function doc and update this step. Thanks