generated from CodeYourFuture/Module-Template
-
-
Notifications
You must be signed in to change notification settings - Fork 330
Sheffield | 26-ITP-jan | Richard Frimpong | Sprint 1 | Structuring and Testing Data #1073
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
Richiealx
wants to merge
17
commits into
CodeYourFuture:main
Choose a base branch
from
Richiealx: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.
+326
−10
Open
Changes from all commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
c106376
Sprint 1: start learning log
Richiealx 21f7d70
Sprint 1 exercises: explain assignment in 1-count.js
Richiealx 39c0fc6
Sprint 1 exercises: complete 2-initials.js and log redeclaration error
Richiealx df378aa
Sprint 1 exercises: complete 3-paths.js using slice and lastIndexOf
Richiealx 58524cd
Sprint 1 exercises: complete 4-random.js with explanation
Richiealx 1dae459
Sprint 1 learning log update
Richiealx c9913f5
Sprint 1 errors: explain 0.js syntax error
Richiealx 723da0c
Sprint 1 errors: explain 1.js const reassignment error
Richiealx 245bf0f
Sprint 1 errors: explain 2.js temporal dead zone error
Richiealx 4582d80
Sprint 1 errors: explain 3.js slice type error
Richiealx 3430d65
Sprint 1 errors: explain 4.js identifier syntax error
Richiealx e1e4a85
Sprint 1 interpret: notes for 1-percentage-change
Richiealx 096e722
Sprint 1 interpret: complete 2-time-format
Richiealx 0b6948d
Sprint 1 interpret: complete 3-to-pounds breakdown
Richiealx 1749f57
Sprint 1 stretch: chrome console object exploration
Richiealx e8f5887
Sprint 1 stretch: object exploration notes
Richiealx 82a4cf1
Sprint 1 interpret: fix percentage-change syntax and tidy notes
Richiealx 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 |
|---|---|---|
| @@ -0,0 +1,49 @@ | ||
| # Sprint 1 — Mandatory Errors (Explanations) | ||
|
|
||
| ## 0.js | ||
| - Error shown: | ||
| - Why it happens: | ||
| - MDN link (optional): | ||
| - Error shown: `SyntaxError: Unexpected identifier 'is'` on line 1. | ||
| - Why it happens: The file begins with plain English text that is not inside a comment or a quoted string. Node tries to interpret it as JavaScript code, but `This is ...` is not valid JS syntax, so parsing fails. | ||
| - MDN link (optional): https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Errors/Unexpected_token | ||
|
|
||
| ## 1.js | ||
| - Error shown: | ||
| - Why it happens: | ||
| - MDN link (optional): | ||
| - Error shown: `TypeError: Assignment to constant variable.` on line 4. | ||
| - Why it happens: The variable `age` was declared with `const`, which prevents reassignment. The statement `age = age + 1` attempts to update the value, causing the error. | ||
| - MDN link (optional): https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/const | ||
|
|
||
| ## 2.js | ||
| - Error shown: | ||
| - Why it happens: | ||
| - MDN link (optional): | ||
| - Error shown: `ReferenceError: Cannot access 'cityOfBirth' before initialization`. | ||
| - Why it happens: The variable `cityOfBirth` is declared later in the file using `let` or `const`, but it is used before that declaration. JavaScript does not allow access to `let`/`const` variables before initialization (temporal dead zone). | ||
| - MDN link: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Errors/Cant_access_lexical_declaration_before_init | ||
|
|
||
|
|
||
| ## 3.js | ||
| - Error shown: | ||
| - Why it happens: | ||
| - MDN link (optional): | ||
| ### 3.js | ||
|
|
||
| - Error shown: `TypeError: cardNumber.slice is not a function` | ||
| - Why it happens: The variable `cardNumber` is a number, and numbers do not have the `slice()` method. The `slice()` method is only available on strings and arrays. | ||
| - Concept: Methods depend on data types in JavaScript. | ||
| - MDN link: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/slice | ||
|
|
||
|
|
||
| ## 4.js | ||
| - Error shown: | ||
| - Why it happens: | ||
| - MDN link (optional): | ||
| ### 4.js | ||
|
|
||
| - Error shown: `SyntaxError: Invalid or unexpected token` | ||
| - Why it happens: The variable name `12HourClockTime` starts with a number. JavaScript identifiers cannot begin with a digit, so the parser throws a syntax error. | ||
| - Concept: Variable naming rules (identifiers must start with a letter, `_`, or `$`) | ||
| - MDN link: https://developer.mozilla.org/en-US/docs/Glossary/Identifier |
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 |
|---|---|---|
| @@ -0,0 +1,155 @@ | ||
| # Sprint 1 — Mandatory Interpret (Notes) | ||
|
|
||
| ## 1-percentage-change.js | ||
| - What the program does: | ||
| - Inputs: | ||
| - Output: | ||
| - Unfamiliar syntax (with link): | ||
| - What I changed / why: | ||
|
|
||
|
|
||
| ## 2-time-format.js | ||
| - What the program does: | ||
| - Inputs: | ||
| - Output: | ||
| - Unfamiliar syntax (with link): | ||
| - What I changed / why: | ||
|
|
||
| ## 3-to-pounds.js | ||
| - What the program does: | ||
| - Inputs: | ||
| - Output: | ||
| - Unfamiliar syntax (with link): | ||
| - What I changed / why: | ||
|
|
||
|
|
||
| ## 1-percentage-change.js | ||
|
|
||
| ### a) How many function calls are there? | ||
| There are 5 function calls: | ||
| - Number(carPrice.replaceAll(",", "")) | ||
| - carPrice.replaceAll(",", "") | ||
| - Number(priceAfterOneYear.replaceAll(",", "")) | ||
| - priceAfterOneYear.replaceAll(",", "") | ||
| - console.log(...) | ||
|
|
||
| --- | ||
|
|
||
| ### b) Where did the error occur and why? | ||
| The error occurred on the line: | ||
| priceAfterOneYear = Number(priceAfterOneYear.replaceAll("," "")); | ||
|
|
||
| The replaceAll function was missing a comma between its arguments. The correct syntax requires two arguments: replaceAll(search, replacement). | ||
|
|
||
| Fix: | ||
| priceAfterOneYear = Number(priceAfterOneYear.replaceAll(",", "")); | ||
|
|
||
| --- | ||
|
|
||
| ### c) Variable reassignment statements | ||
| - carPrice = Number(carPrice.replaceAll(",", "")) | ||
| - priceAfterOneYear = Number(priceAfterOneYear.replaceAll(",", "")) | ||
|
|
||
| --- | ||
|
|
||
| ### d) Variable declarations | ||
| - let carPrice = "10,000" | ||
| - let priceAfterOneYear = "8,543" | ||
| - const priceDifference = carPrice - priceAfterOneYear | ||
| - const percentageChange = (priceDifference / carPrice) * 100 | ||
|
|
||
| --- | ||
|
|
||
| ### e) What does Number(carPrice.replaceAll(",", "")) do? | ||
| First, replaceAll(",", "") removes commas from the string "10,000", producing "10000". | ||
| Then, Number(...) converts the string "10000" into the numeric value 10000. | ||
| This ensures arithmetic operations can be performed correctly. | ||
|
|
||
|
|
||
|
|
||
| ## 2-time-format.js | ||
|
|
||
| ### a) How many variable declarations? | ||
| There are 6 variable declarations: | ||
| - movieLength | ||
| - remainingSeconds | ||
| - totalMinutes | ||
| - remainingMinutes | ||
| - totalHours | ||
| - result | ||
|
|
||
| --- | ||
|
|
||
| ### b) How many function calls? | ||
| There is 1 function call: | ||
| - console.log(result) | ||
|
|
||
| --- | ||
|
|
||
| ### c) What does movieLength % 60 represent? | ||
| The % operator returns the remainder after division. | ||
| movieLength % 60 gives the number of seconds left after converting full minutes. | ||
| In this example, it returns 24 seconds. | ||
|
|
||
| --- | ||
|
|
||
| ### d) Interpret line 4 (totalMinutes) | ||
| const totalMinutes = (movieLength - remainingSeconds) / 60; | ||
|
|
||
| This subtracts the leftover seconds from the total seconds and divides by 60. | ||
| The result is the total number of full minutes in the movie. | ||
|
|
||
| --- | ||
|
|
||
| ### e) What does result represent? Better name? | ||
| The variable result represents the formatted movie duration in hours:minutes:seconds. | ||
| A better name could be: | ||
| - formattedTime | ||
| - movieDuration | ||
| - durationString | ||
|
|
||
| --- | ||
|
|
||
| ### f) Will this work for all values of movieLength? | ||
| Yes, it works for any positive number of seconds. | ||
| However, if movieLength is negative, a decimal, or not a number, the result would be incorrect. | ||
| Also, minutes and seconds are not padded with leading zeros, so values like 2:3:5 may appear instead of 02:03:05. | ||
|
|
||
|
|
||
|
|
||
|
|
||
| ## 3-to-pounds.js | ||
|
|
||
| 1) `const penceString = "399p";` | ||
| - Declares a string containing a price in pence, with a trailing `p` character. | ||
|
|
||
| 2) `const penceStringWithoutTrailingP = penceString.substring(0, penceString.length - 1);` | ||
| - Takes a substring from index 0 up to (but not including) the last character. | ||
| - Purpose: remove the trailing `"p"`. | ||
| - For `"399p"`, this becomes `"399"`. | ||
|
|
||
| 3) `const paddedPenceNumberString = penceStringWithoutTrailingP.padStart(3, "0");` | ||
| - Pads the string on the left until it is at least length 3, using `"0"`. | ||
| - Purpose: make sure we always have enough digits to represent pounds + pence. | ||
| - Example: `"5"` becomes `"005"`, `"50"` becomes `"050"`, `"399"` stays `"399"`. | ||
|
|
||
| 4) `const pounds = paddedPenceNumberString.substring(0, paddedPenceNumberString.length - 2);` | ||
| - Takes everything except the last 2 digits. | ||
| - Purpose: the part before the last 2 digits is the pounds. | ||
| - For `"399"`, length is 3, so substring(0, 1) → `"3"`. | ||
|
|
||
| 5) `const pence = paddedPenceNumberString.substring(paddedPenceNumberString.length - 2).padEnd(2, "0");` | ||
| - First, `substring(length - 2)` takes the last 2 digits. | ||
| - Then `padEnd(2, "0")` ensures it’s at least 2 characters (adds zeros on the right if needed). | ||
| - Purpose: get exactly two pence digits. | ||
| - For `"399"`, last two digits are `"99"` → stays `"99"`. | ||
|
Comment on lines
+141
to
+145
Contributor
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. Could we expect this program to work as intended for any valid |
||
|
|
||
| 6) `console.log(\`£${pounds}.${pence}\`);` | ||
| - Uses a template literal to format the final currency string as pounds and pence. | ||
| - For pounds `"3"` and pence `"99"` → outputs `£3.99`. | ||
|
|
||
| ### Unfamiliar syntax (docs) | ||
| - substring: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/substring | ||
| - padStart: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/padStart | ||
| - padEnd: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/padEnd | ||
| - template literals: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Template_literals | ||
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 |
|---|---|---|
| @@ -0,0 +1,72 @@ | ||
| ## chrome.md | ||
|
|
||
| ### What the task asked me to do | ||
| Explore the Chrome DevTools console and investigate what the console object stores and how dot notation works. | ||
|
|
||
| --- | ||
|
|
||
| ### What I did (steps) | ||
| 1. Opened Chrome DevTools and navigated to the Console tab. | ||
| 2. Entered `console.log` and observed that it returned a function. | ||
| 3. Entered `console` and observed that it returned an object with multiple methods such as log, warn, error, and assert. | ||
| 4. Entered `typeof console` and confirmed that console is an object. | ||
|
|
||
| --- | ||
|
|
||
| ### What I learned | ||
| - `console` stores an object containing many methods used for debugging. | ||
| - `console.log`, `console.assert`, etc. are functions stored inside the console object. | ||
| - The `.` operator is called dot notation and is used to access properties or methods of an object. | ||
|
|
||
| --- | ||
|
|
||
| ### Useful links | ||
| - https://developer.mozilla.org/en-US/docs/Web/API/Console | ||
| - https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Working_with_objects | ||
|
|
||
|
|
||
|
|
||
| ## objects.md | ||
|
|
||
| ### What output did I get? | ||
|
|
||
| - `console.log` → returned a function definition (ƒ log() { [native code] }) | ||
| - `console` → returned an object with many methods such as log, warn, error, assert | ||
| - `typeof console` → returned "object" | ||
|
|
||
| --- | ||
|
|
||
| ### What does `console` store? | ||
| The console variable stores an object that contains multiple debugging methods. These methods allow developers to print messages, warnings, errors, and other diagnostic information in the browser console. | ||
|
|
||
| --- | ||
|
|
||
| ### What does `console.log` or `console.assert` mean? | ||
| These expressions use dot notation to access methods inside the console object. | ||
| For example: | ||
| - `console.log` accesses the log function | ||
| - `console.assert` accesses the assert function | ||
|
|
||
| --- | ||
|
|
||
| ### What does the `.` mean? | ||
| The dot operator is called dot notation. | ||
| It is used to access properties or methods of an object. | ||
|
|
||
| So: | ||
| - `console` is the object | ||
| - `log` is a method inside that object | ||
| - `console.log` means "access the log method from the console object" | ||
|
|
||
| --- | ||
|
|
||
| ### What I learned | ||
| - Objects store related data and functions together | ||
| - The browser console itself is an object | ||
| - Dot notation is how we interact with object properties and methods | ||
|
|
||
| --- | ||
|
|
||
| ### Useful links | ||
| - https://developer.mozilla.org/en-US/docs/Web/API/Console | ||
| - https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Working_with_objects |
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 |
|---|---|---|
| @@ -0,0 +1,16 @@ | ||
| # Sprint 1 — Learning Log | ||
|
|
||
| ## What I learned | ||
| - Started Sprint 1 exercises and set up coursework branch | ||
| - Learned how to extract directory and extension from a file path using lastIndexOf and slice. | ||
| - How Math.random(), Math.floor(), and arithmetic combine to generate a random integer in a range | ||
|
|
||
|
|
||
| ## Errors I hit and what they mean## What I learned | ||
|
|
||
|
|
||
| ## Docs I used (links) | ||
| - | ||
|
|
||
| ## Questions for class | ||
| - |
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?