-
-
Notifications
You must be signed in to change notification settings - Fork 546
Cape Town | 26-ITP-Sep | Quentin Gwele | Sprint 3 | coursework: sprint 3 #1592
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
lwandogwele52-ui
wants to merge
10
commits into
CodeYourFuture:main
Choose a base branch
from
lwandogwele52-ui: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
10 commits
Select commit
Hold shift + click to select a range
f7295fe
Complete Sprint-3 errors exercise (0.js, 1.js, 2.js)
lwandogwele52-ui a25a455
Complete Sprint-3 debug exercises (0.js, 1.js, 2.js)
lwandogwele52-ui f1b09e3
Complete Sprint-3 implement exercises (1-bmi.js, 2-cases.js, 3-to-pou…
lwandogwele52-ui 28c7638
Complete Sprint-3 interpret exercise (time-format.js)
lwandogwele52-ui b74b98b
Complete Sprint-3 stretch-extend exercise (format-time.js)
lwandogwele52-ui 42903a4
Fix formatAs12HourClock logic in Sprint 3
lwandogwele52-ui 008bc6e
Fix 12-hour clock: pad hours and handle midnight and noon
lwandogwele52-ui 352fee7
Implement toPounds to convert pence string to pounds
lwandogwele52-ui ddfce92
Fix getLastDigit to accept num parameter
lwandogwele52-ui 3443faf
Use negative index in slice for minutes to handle variable-length hours
lwandogwele52-ui 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,24 @@ | ||
| // Predict and explain first... | ||
| // =============> write your prediction here | ||
| // ==============> write your prediction here | ||
| // I predict this will throw a SyntaxError, because the parameter 'str' is | ||
| // being redeclared with 'let' inside the function. | ||
|
|
||
| // 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)}`; | ||
| return str; | ||
| let result = `${str[0].toUpperCase()}${str.slice(1)}`; | ||
| return result; | ||
| } | ||
|
|
||
| // =============> write your explanation here | ||
| // =============> write your new code here | ||
| console.log(capitalise("hello")); | ||
|
|
||
| // ==============> write your explanation here | ||
| // The parameter 'str' already existed in the function's scope. The original | ||
| // code tried to declare another variable with 'let str', which caused a | ||
| // naming collision — JavaScript doesn't allow redeclaring a variable with | ||
| // 'let' in the same scope. This threw a SyntaxError before the function | ||
| // could even run. Renaming the new variable to 'result' fixes the collision. | ||
|
|
||
| // ==============> write your new code here | ||
| // (the fixed function above already satisfies this) |
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,33 @@ | ||
| // Predict and explain first... | ||
|
|
||
| // Why will an error occur when this program runs? | ||
| // =============> write your prediction here | ||
| // ==============> write your prediction here | ||
| // I predict this will throw a SyntaxError, because 'decimalNumber' is being | ||
| // redeclared with 'const' inside the function, even though it's already the | ||
| // function's parameter. | ||
|
|
||
| // Try playing computer with the example to work out what is going on | ||
|
|
||
| function convertToPercentage(decimalNumber) { | ||
| const decimalNumber = 0.5; | ||
| const percentage = `${decimalNumber * 100}%`; | ||
|
|
||
| return percentage; | ||
| } | ||
|
|
||
| console.log(decimalNumber); | ||
| console.log(convertToPercentage(0.5)); | ||
|
|
||
| // =============> write your explanation here | ||
| // ==============> write your explanation here | ||
| // 'decimalNumber' was already declared as the function's parameter. The | ||
| // original code tried to declare another variable with the same name using | ||
| // 'const decimalNumber = 0.5;', which caused a naming collision — JavaScript | ||
| // doesn't allow redeclaring a variable in the same scope. This threw a | ||
| // SyntaxError before the function could run. | ||
| // | ||
| // There was also a second issue: the original 'console.log(decimalNumber);' | ||
| // was outside the function, so 'decimalNumber' didn't exist there (it's | ||
| // scoped only inside 'convertToPercentage'), and the function was never | ||
| // actually called. The fix removes the duplicate declaration and calls | ||
| // convertToPercentage(0.5) directly, logging its return value instead. | ||
|
|
||
| // Finally, correct the code to fix the problem | ||
| // =============> write your new code here | ||
| // ==============> write your new code here | ||
| // (the fixed function above already satisfies this) |
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,31 @@ | ||
|
|
||
| // Predict and explain first BEFORE you run any code... | ||
|
|
||
| // this function should square any number but instead we're going to get an error | ||
|
|
||
| // =============> write your prediction of the error here | ||
| // this function should square any number but instead we're getting an error | ||
| // ==============> write your prediction of the error here | ||
| // I predict this will throw a SyntaxError, because '3' is used as the | ||
| // parameter name in 'function square(3)', and a number can't be used as a | ||
| // parameter name — parameter names must be valid identifiers (like variable | ||
| // names). | ||
|
|
||
| function square(3) { | ||
| return num * num; | ||
| function square(num) { | ||
| return num * num; | ||
| } | ||
|
|
||
| // =============> write the error message here | ||
|
|
||
| // =============> explain this error message here | ||
| console.log(square(3)); | ||
|
|
||
| // Finally, correct the code to fix the problem | ||
|
|
||
| // =============> write your new code here | ||
| // ==============> write the error message here | ||
| // SyntaxError: Unexpected number | ||
|
|
||
| // ==============> explain this error message here | ||
| // Function parameters must be valid identifiers — the same rules as variable | ||
| // names (they must start with a letter, '$', or '_', never a digit). The | ||
| // original code used '3' as the parameter name, which isn't a valid | ||
| // identifier, so JavaScript couldn't even parse the function definition. | ||
| // This error happens before any code runs. There was also a second bug: the | ||
| // function body referred to 'num', which didn't match the (invalid) | ||
| // parameter name at all — fixing the parameter name to 'num' resolves both | ||
| // issues at once. | ||
|
|
||
| // Finally, correct the code to fix the problem | ||
| // ==============> write your new code here | ||
| // (the fixed function above already satisfies this) |
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,26 @@ | ||
| // Predict and explain first... | ||
|
|
||
| // =============> write your prediction here | ||
| // ==============> write your prediction here | ||
| // I predict this will run without an error, but print the wrong result at | ||
| // the end. The 'multiply' function uses console.log internally instead of | ||
| // returning a value, so when it's used inside the template literal, it will | ||
| // show as 'undefined' instead of the actual multiplication result. | ||
|
|
||
| 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 | ||
| // ==============> write your explanation here | ||
| // The original 'multiply' function printed the result with console.log | ||
| // instead of returning it. A function that doesn't explicitly return a value | ||
| // returns 'undefined' by default. When the outer console.log tried to use | ||
| // multiply(10, 32) inside the template literal, it inserted 'undefined' | ||
| // instead of the actual number, because it was using the function's return | ||
| // value, not what it printed internally. Changing console.log to return | ||
| // inside the function fixes this, since now the function actually hands | ||
| // back the calculated value. | ||
|
|
||
| // Finally, correct the code to fix the problem | ||
| // =============> write your new code here | ||
| // ==============> write your new code here | ||
| // (the fixed function above already satisfies this) |
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,27 @@ | ||
| // Predict and explain first... | ||
| // =============> write your prediction here | ||
| // ==============> write your prediction here | ||
| // I predict this will run without an error, but the result will show as | ||
| // 'undefined' instead of the actual sum. The 'return' statement is on its | ||
| // own line, separate from 'a + b;' on the next line — JavaScript will treat | ||
| // these as two separate statements, so the function returns immediately | ||
| // with nothing, and 'a + b' never actually gets returned. | ||
|
|
||
| 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 | ||
| // ==============> write your explanation here | ||
| // JavaScript has a feature called Automatic Semicolon Insertion (ASI). When | ||
| // 'return' appears on its own line with nothing after it, JavaScript | ||
| // automatically treats it as 'return;' — ending the function right there and | ||
| // returning 'undefined'. The following line, 'a + b;', becomes dead code | ||
| // that never runs, because the function has already exited. This is why the | ||
| // original code always produced 'undefined' instead of the sum. The fix is | ||
| // to put the expression on the same line as 'return', so JavaScript knows | ||
| // it's part of the return statement: 'return a + b;'. | ||
|
|
||
| // Finally, correct the code to fix the problem | ||
| // =============> write your new code here | ||
| // ==============> write your new code here | ||
| // (the fixed function above already satisfies this) |
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
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.
Uh oh!
There was an error while loading. Please reload this page.