generated from CodeYourFuture/Module-Template
-
-
Notifications
You must be signed in to change notification settings - Fork 195
LONDON | May-2025 | Sisay Mehari | Module-Structuring-and-Testing-Data | Sprint-1 #505
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
Sisu860
wants to merge
17
commits into
CodeYourFuture:main
Choose a base branch
from
Sisu860: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
17 commits
Select commit
Hold shift + click to select a range
34e9cdd
Answer question to count exercise.
Sisu860 f410da4
Add counter increment logic
Sisu860 eb12f81
Extract initials from names using indexing
Sisu860 808b276
clarify random number generation logic
Sisu860 7cfefd4
comment out non-executable instructions
Sisu860 b90784d
replace const with let for mutable age variable
Sisu860 e2de90d
fix: variable declaration order
Sisu860 474cd7c
convert cardNumber to string before slicing to extract last 4 digits
Sisu860 1243e03
fix: rename time variables to comply with JS naming rules
Sisu860 6f5b62f
Add JavaScript code analysis and corrections
Sisu860 bcf1740
Add utility to convert seconds to HH:MM:SS format
Sisu860 cbd9de0
Implement pence to pounds currency formatting
Sisu860 07f3b56
Add explanation of browser alert() and prompt() functions
Sisu860 90abf10
Explain console object, methods, and dot notation
Sisu860 2792c56
Update 1.js
Sisu860 9269348
Add age += increment example
Sisu860 5435e87
Implement review suggestions
Sisu860 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? | ||
//To make sure the computer doesn't run them, I turned them into comments using // so they’re ignored by the JavaScript engine. |
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,6 @@ | ||
// trying to create an age variable and then reassign the value by 1 | ||
|
||
const age = 33; | ||
let age = 33; | ||
age = age + 1; | ||
//Or we can use like this | ||
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,26 @@ | ||
// Currently trying to print the string "I was born in Bolton" but it isn't working... | ||
// what's the error ? | ||
/* | ||
QUESTION: | ||
The following code fails to print "I was born in Bolton". What's the error? | ||
|
||
console.log(`I was born in ${cityOfBirth}`); | ||
console.log(`I was born in ${cityOfBirth}`); | ||
const cityOfBirth = "Bolton"; | ||
|
||
ANSWER: | ||
The error occurs because: | ||
1. We're trying to use 'cityOfBirth' before it's declared | ||
2. const/let variables can't be accessed before declaration (Temporal Dead Zone) | ||
|
||
SOLUTION: | ||
const cityOfBirth = "Bolton"; // Declare first | ||
console.log(`I was born in ${cityOfBirth}`); // Now works | ||
|
||
EXPLANATION: | ||
- Order matters in JavaScript for const/let variables | ||
- The fixed version follows proper variable declaration order | ||
- This avoids the Temporal Dead Zone reference error | ||
- Output will now correctly show: "I was born in Bolton" | ||
*/ | ||
|
||
// Corrected implementation: | ||
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
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,22 @@ | ||
const 12HourClockTime = "20:53"; | ||
const 24hourClockTime = "08:53"; | ||
// Problem Case (invalid syntax): | ||
// const 12HourClockTime = "20:53"; // ❌ SyntaxError: Invalid variable name | ||
// const 24hourClockTime = "08:53"; // ❌ Also invalid (starts with number) | ||
|
||
// Solution: | ||
const twelveHourClockTime = "08:53"; // ✅ Valid (starts with letter) | ||
const twentyFourHourClockTime = "20:53"; // ✅ Valid | ||
|
||
/* Explanation: | ||
1. JavaScript variable naming rules: | ||
- Cannot start with a digit (0-9) | ||
- Must start with letter, underscore (_), or dollar sign ($) | ||
|
||
2. Fix approach: | ||
- Changed numeric prefixes to words ("twelve" instead of 12) | ||
- Maintained clear, descriptive names | ||
- Kept the same time values as strings | ||
|
||
3. Why strings are appropriate: | ||
- Time formats with colons are best represented as strings | ||
- No arithmetic operations needed on these values | ||
*/ |
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 |
---|---|---|
|
@@ -12,8 +12,7 @@ const pounds = paddedPenceNumberString.substring( | |
); | ||
|
||
const pence = paddedPenceNumberString | ||
.substring(paddedPenceNumberString.length - 2) | ||
.padEnd(2, "0"); | ||
.substring(paddedPenceNumberString.length - 2); | ||
|
||
console.log(`£${pounds}.${pence}`); | ||
|
||
|
@@ -25,3 +24,21 @@ console.log(`£${pounds}.${pence}`); | |
|
||
// To begin, we can start with | ||
// 1. const penceString = "399p": initialises a string variable with the value "399p" | ||
// This value represents a monetary amount in pence, with a trailing "p" to indicate "pence" (e.g., 399 pence). | ||
// 2. const penceStringWithoutTrailingP = penceString.substring(0, penceString.length - 1); | ||
// This line removes the last character ("p") from the penceString. | ||
// It uses .substring() to extract all characters from index 0 up to (but not including) the final character. | ||
// Purpose: To isolate the numeric portion of the string so that calculations can be performed. | ||
// 3. const paddedPenceNumberString = penceStringWithoutTrailingP.padStart(3, "0"); | ||
// This line ensures the string has at least 3 characters by adding "0" to the start if it's too short. | ||
// Rationale: This guarantees that the number has enough digits to split correctly into pounds and pence, even if the original number is small (e.g., "5p" becomes "005"). | ||
// 4. const pounds = paddedPenceNumberString.substring(0, paddedPenceNumberString.length - 2); | ||
// This line extracts the pounds part by slicing the string from the beginning up to the last 2 characters. | ||
// Rationale: In UK currency, the last two digits represent pence, and the digits before that represent pounds. | ||
// 5. const pence = paddedPenceNumberString.substring(paddedPenceNumberString.length - 2); | ||
// This line extracts the last 2 characters as the pence part. | ||
// If for any reason it's shorter than 2 digits, it adds a "0" to the end to ensure the format is correct. | ||
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. What reason would it be? |
||
// Purpose: Guarantees a consistent two-digit pence value. | ||
// 6. console.log(`£${pounds}.${pence}`); | ||
// This line constructs and prints the final price string in pounds and pence format, using template literals. | ||
// Rationale: This is the output the user will see, displaying the price in standard British currency format (e.g., £3.99). |
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.
what is
dotIndex
?