-
-
Notifications
You must be signed in to change notification settings - Fork 546
Cape Town | 26-ITP-Sept | Lamla Kamana | Sprint 3 | Coursework/sprint 3 #1615
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
lamlakamana-oss
wants to merge
24
commits into
CodeYourFuture:main
Choose a base branch
from
lamlakamana-oss:coursework/sprint-3
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
24 commits
Select commit
Hold shift + click to select a range
69c00ce
fix key error in 0.js - duplicate str variable
lamlakamana-oss 01b0572
fix key error in 1.js - duplicate decimalNumber variable and scope issue
lamlakamana-oss 468f39f
Fix 2.js: use a parameter name instead of a number
lamlakamana-oss d207836
Fix 2-mandatory-debug/0.js: return the product instead of logging it
lamlakamana-oss 8f610f3
Fix 2-mandatory-debug/1.js: put return value on the same line
lamlakamana-oss 69f740e
Fix 2-mandatory-debug/2.js: add num parameter to getLastDigit
lamlakamana-oss 01ee9fd
Implement calculateBMI in 3-mandatory-implement/1-bmi.js
lamlakamana-oss a37a324
Implement toUpperSnakeCase in 3-mandatory-implement/2-cases.js
lamlakamana-oss 80cb798
Implement toPounds in 3-mandatory-implement/3-to-pounds.js
lamlakamana-oss a4bab84
Answer questions in 4-mandatory-interpret/time-format.js
lamlakamana-oss 552c37c
Add comprehensive edge case tests for 12-hour clock
lamlakamana-oss 6bc1c9c
Answer question e and rename result variable
lamlakamana-oss b76934a
Revert "Answer question e and rename result variable"
lamlakamana-oss 5cc752a
Add actual error output and deeper TDZ explanation
lamlakamana-oss d18dbb8
Fixed shadowing issue and added corrected code
lamlakamana-oss 82cfcc6
Updated BMI calculation to use exponentiation operator
lamlakamana-oss 6736f52
Added blank line for readability
lamlakamana-oss e2053ed
Removed redundant padEnd on pence calculation
lamlakamana-oss 908f258
Added readability comment, blank line, and fixed header text
lamlakamana-oss c983ebd
Fixed time logic, added edge case tests, and labeled tests 1 and 2
lamlakamana-oss 87b77ed
Cleaned up ASI explanation
lamlakamana-oss 4634977
Removed reference to specific line number in comment
lamlakamana-oss 297d063
Removed extra parentheses and line number reference
lamlakamana-oss b2459ed
Added actual error output to comments and restored working code
lamlakamana-oss 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,13 +1,35 @@ | ||
| // Predict and explain first... | ||
| // =============> write your prediction here | ||
| //I think this code will show a SyntaxError. The function has two variables named str in the same scope. | ||
| // ACTUAL ERROR (running the original code with `node 0.js`): | ||
| // C:\Users\EarthHarvestAdmin\CYF2026 LAMLA KAMANA\Module-JavaScript-Fundamentals\Sprint-3\1-key-errors\0.js:8 | ||
| let str = `${str[0].toUpperCase()}${str.slice(1)}`; | ||
| ^ | ||
|
|
||
| //SyntaxError: Identifier 'str' has already been declared | ||
|
|
||
| // WHY IT IS ILLEGAL (DEEPER EXPLANATION): | ||
| // 1. SCOPE COLLISION: The function parameter `str` and the variable `let str` | ||
| // exist in the exact same function scope. In JavaScript, `let` and `const` | ||
| // do NOT allow redeclaring an existing variable in the same scope. | ||
| // | ||
| // 2. TEMPORAL DEAD ZONE (TDZ): When the JavaScript engine parses this function, | ||
| // it hoists the `let str` declaration to the top of the function scope. | ||
| // However, unlike `var`, `let` variables remain in an uninitialized state | ||
| // (the TDZ) until the exact line of declaration is executed. | ||
| // | ||
| // 3. FATAL PARSING ERROR: Because this is a SyntaxError (not a runtime error), | ||
| // the JavaScript engine catches the illegal redeclaration during the | ||
| // compilation/parsing phase, BEFORE any code executes. This is why the | ||
| // `console.log` on line 12 never runs—the script never gets past the | ||
| // parsing stage. | ||
| // | ||
| // FIX: use a different name for the new variable, e.g. `result`. | ||
| // call the function capitalise with a string input | ||
| // interpret the error message and figure out why an error is occurring | ||
|
|
||
| function capitalise(str) { | ||
| let str = `${str[0].toUpperCase()}${str.slice(1)}`; | ||
| let str = `${str[0].toUpperCase()}${str.slice(1)}`; | ||
| return str; | ||
| } | ||
|
|
||
| // =============> write your explanation here | ||
| // =============> write your new code here | ||
| console.log(capitalise("hello")); | ||
| // str is used both as the function parameter (function capitalise(str)) and again in let str = ... |
|
lamlakamana-oss marked this conversation as resolved.
|
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,20 +1,24 @@ | ||
| // Predict and explain first... | ||
|
|
||
| // Why will an error occur when this program runs? | ||
| // =============> write your prediction here | ||
| // I predict this will cause a SyntaxError first (at parse time) because | ||
| // decimalNumber is declared twice in the same scope. | ||
|
|
||
| // Try playing computer with the example to work out what is going on | ||
| // Once the SyntaxError is fixed, a ReferenceError will appear at runtime. | ||
| // This is because we would need to rename one of the variables so the | ||
| // function can actually use it. | ||
|
|
||
| function convertToPercentage(decimalNumber) { | ||
| const decimalNumber = 0.5; | ||
| const percentage = `${decimalNumber * 100}%`; | ||
|
|
||
| const percentage = `${decimalNumber * 100}%`; | ||
| return percentage; | ||
| } | ||
|
|
||
| console.log(decimalNumber); | ||
| console.log(convertToPercentage(0.5)); | ||
|
|
||
| // =============> write your explanation here | ||
| // decimalNumber is declared twice in the same scope, once as the function's parameter, and again with const inside the function body. JavaScript doesn't allow redeclaring the same name in the same scope. Even after fixing that, console.log(decimalNumber) would fail too, because decimalNumber only exists inside the function. | ||
| //ACTUAL ERROR (SyntaxError):. | ||
| // C:\Users\EarthHarvestAdmin\CYF2026 LAMLA KAMANA\Module-JavaScript-Fundamentals\Sprint-3\1-key-errors\1.js:12 | ||
| // const decimalNumber = `$ {decimalNumber * 100}%`; | ||
| // ^ | ||
|
|
||
| // Finally, correct the code to fix the problem | ||
| // =============> write your new code here | ||
| // SyntaxError: Identifier 'decimalNumber' has already been declared |
|
lamlakamana-oss marked this conversation as resolved.
|
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
|
lamlakamana-oss marked this conversation as resolved.
|
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,14 +1,23 @@ | ||
| // Predict and explain first... | ||
|
|
||
| // =============> write your prediction here | ||
| // I predict it will print 320 first (from the console.log inside multiply), | ||
| // and then "The result of multiplying 10 and 32 is undefined", because | ||
| // multiply does not return a value. | ||
|
|
||
| function multiply(a, b) { | ||
| console.log(a * b); | ||
| return a * b; | ||
| } | ||
|
|
||
| console.log(`The result of multiplying 10 and 32 is ${multiply(10, 32)}`); | ||
|
|
||
| // =============> write your explanation here | ||
| // multiply only logs a * b to the console. It has no return statement, so | ||
| // multiply(10, 32) evaluates to undefined. The template string in the console.log | ||
| // puts that undefined into the sentence. The 320 appears on its own line | ||
| // because console.log runs inside the function. | ||
|
|
||
| // Finally, correct the code to fix the problem | ||
| // =============> write your new code here | ||
| // I changed console.log(a * b) to return a * b inside multiply, so the | ||
| // function hands the result back to the caller instead of only printing it. |
|
lamlakamana-oss marked this conversation as resolved.
|
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,13 +1,19 @@ | ||
| // Predict and explain first... | ||
| // =============> write your prediction here | ||
| // I predict it will print "The sum of 10 and 32 is undefined", because | ||
| // the function returns before it reaches a + b. | ||
|
|
||
| function sum(a, b) { | ||
| return; | ||
| a + b; | ||
| return a + b; | ||
| } | ||
|
|
||
| console.log(`The sum of 10 and 32 is ${sum(10, 32)}`); | ||
|
|
||
| // =============> write your explanation here | ||
| // The return statement was on its own line with nothing after it, so the | ||
| // function returned undefined straight away. This is caused by automatic | ||
| // semicolon insertion (ASI), where JavaScript treats the line break after | ||
| // 'return' as the end of the statement, so 'a + b' was never reached. | ||
| // Finally, correct the code to fix the problem | ||
| // =============> write your new code here | ||
| // I moved a + b onto the same line as return: return a + b |
|
lamlakamana-oss marked this conversation as resolved.
|
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
|
lamlakamana-oss marked this conversation as resolved.
|
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
|
lamlakamana-oss marked this conversation as resolved.
|
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
|
lamlakamana-oss marked this conversation as resolved.
|
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
|
lamlakamana-oss marked this conversation as resolved.
|
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
|
lamlakamana-oss marked this conversation as resolved.
|
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.
Uh oh!
There was an error while loading. Please reload this page.