Repository navigation
Manchester | 26-ITP-Sept | Fatima Rouchi | Sprint 3 | Coursework/sprint 3 #1634
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
fatimarouchi
wants to merge
24
commits into
CodeYourFuture:main
Choose a base branch
from
fatimarouchi: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
c85f975
complete ex 0.js
fatimarouchi e071e69
complete ex 1.js
fatimarouchi 6570ced
write prediction for 2.js
fatimarouchi 001939b
complete ex 2.js
fatimarouchi 9650964
complete ex 0.js
fatimarouchi af75a19
complete ex 1.js
fatimarouchi 12f14c1
complete ex 2.js
fatimarouchi cdac639
complete ex 1-bmi.js
fatimarouchi 4089ba3
complete ex. 2-cases.js
fatimarouchi acc0e01
complete ex 3-to-pounds.js
fatimarouchi f80713c
complete ex time-format.js
fatimarouchi 86827f4
complete ex format-time.js
fatimarouchi 9f55f62
Fix 12-hour clock conversion and add edge-case tests
fatimarouchi c566c35
Fix time conversion
fatimarouchi ebea776
Pad single-digit minutes in time formatter
fatimarouchi d6fd51e
Handle empty strings in capitalise function
fatimarouchi dc6b184
Format percentage output to one decimal place
fatimarouchi 60c1518
Handle multiple spaces in case conversion
fatimarouchi 8ee83a9
Support pence values with or without the p suffix
fatimarouchi 7a70e63
Fix 12-hour time formatting for leading-zero hours
fatimarouchi f7dd186
Fix 12-hour time formatting and tests
fatimarouchi 6270b24
Add UPPER_SNAKE_CASE test cases
fatimarouchi 53bf711
Add BMI checks for multiple inputs
fatimarouchi 1d34e47
Fix percentage formatting
fatimarouchi 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,25 @@ | ||
| // Predict and explain first... | ||
| // =============> write your prediction here | ||
| // =============>// I predict JavaScript will give a SyntaxError because str is declared twice in 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) { | ||
| /*function capitalise(str) { | ||
| let str = `${str[0].toUpperCase()}${str.slice(1)}`; | ||
| return str; | ||
| } | ||
|
|
||
| // =============> write your explanation here | ||
| capitalise("hello");*/ | ||
| /* =============> The error happens because str is already the function's parameter. | ||
| let str tries to use the same name again, so JavaScript gives a SyntaxError. | ||
| The function stops before it can run. */ | ||
| // =============> write your new code here | ||
| function capitalise(str) { | ||
| if (str === "") { | ||
| return ""; | ||
| } | ||
|
|
||
| const result = `${str[0].toUpperCase()}${str.slice(1)}`; | ||
| return result; | ||
| } | ||
|
|
||
| console.log(`Result: "${capitalise("")}"`); |
|
fatimarouchi 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,29 @@ | ||
| // Predict and explain first... | ||
|
|
||
| // Why will an error occur when this program runs? | ||
| // =============> write your prediction here | ||
| // =============>// I predict a SyntaxError because decimalNumber is declared as a parameter and then declared again with const. | ||
|
|
||
| // Try playing computer with the example to work out what is going on | ||
|
|
||
| function convertToPercentage(decimalNumber) { | ||
| /*function convertToPercentage(decimalNumber) { | ||
| const decimalNumber = 0.5; | ||
| const percentage = `${decimalNumber * 100}%`; | ||
|
|
||
| return percentage; | ||
| } | ||
|
|
||
| console.log(decimalNumber); | ||
| console.log(decimalNumber);*/ | ||
|
|
||
| // =============> write your explanation here | ||
| /* =============> decimalNumber is already the function parameter. | ||
| const decimalNumber tries to declare the same name again inside the function, | ||
| so JavaScript gives a SyntaxError. */ | ||
|
|
||
| // Finally, correct the code to fix the problem | ||
| // =============> write your new code here | ||
| function convertToPercentage(decimalNumber) { | ||
| const percentage = `${decimalNumber * 100}%`; | ||
|
|
||
| return percentage; | ||
| } | ||
|
|
||
| console.log(convertToPercentage(0.5)); | ||
|
fatimarouchi marked this conversation as resolved.
|
||
|
fatimarouchi 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,21 @@ | ||
|
|
||
| // 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 | ||
| // =============> // I predict a SyntaxError because 3 is a number, but a function parameter needs to be a name. | ||
|
|
||
| function square(3) { | ||
| /*function square(3) { | ||
| return num * num; | ||
| } | ||
| */ | ||
| // =============> SyntaxError: Unexpected number | ||
|
|
||
| // =============> write the error message here | ||
|
|
||
| // =============> explain this error message here | ||
| // =============> The error happens because 3 is not a name. A parameter needs a name, like num. | ||
|
|
||
| // Finally, correct the code to fix the problem | ||
|
|
||
| // =============> write your new code here | ||
|
|
||
|
|
||
| function square(num) { | ||
| return num * num; | ||
| } | ||
| console.log(square(3)); |
|
fatimarouchi 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,18 @@ | ||
| // Predict and explain first... | ||
|
|
||
| // =============> write your prediction here | ||
| // =============> I couldn't predict until I run the code | ||
|
|
||
| function multiply(a, b) { | ||
| /*function multiply(a, b) { | ||
| console.log(a * b); | ||
| } | ||
|
|
||
| console.log(`The result of multiplying 10 and 32 is ${multiply(10, 32)}`); | ||
|
|
||
| // =============> write your explanation here | ||
| console.log(`The result of multiplying 10 and 32 is ${multiply(10, 32)}`);*/ | ||
|
|
||
| /* =============> The Terminal gives an answer of 320 but also says "The result of multiplying 10 and 32 is undefined" | ||
| which makes me think that the function has no return so it gives back undefined.*/ | ||
| // Finally, correct the code to fix the problem | ||
| // =============> write your new code here | ||
| function multiply(a, b) { | ||
| return a * b; | ||
| } | ||
| console.log(`The result of multiplying 10 and 32 is ${multiply(10, 32)}`); |
|
fatimarouchi 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 the code won't work because there's a ";" after return. | ||
|
|
||
| function sum(a, b) { | ||
| /*function sum(a, b) { | ||
| return; | ||
| a + b; | ||
| } | ||
|
|
||
| console.log(`The sum of 10 and 32 is ${sum(10, 32)}`); | ||
| console.log(`The sum of 10 and 32 is ${sum(10, 32)}`);*/ | ||
|
|
||
| // =============> write your explanation here | ||
| /* =============> The sum is undefined because the semicolon after return ends it too early, | ||
| the function returns before adding a and b.*/ | ||
| // Finally, correct the code to fix the problem | ||
| // =============> write your new code here | ||
| function sum(a, b) { | ||
| return a + b; | ||
| } | ||
|
|
||
| console.log(`The sum of 10 and 32 is ${sum(10, 32)}`); |
|
fatimarouchi 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,24 +1,43 @@ | ||
| // Predict and explain first... | ||
|
|
||
| // Predict the output of the following code: | ||
| // =============> Write your prediction here | ||
| // =============> I predict the result will be wrong because the num is set set on 103. | ||
|
|
||
| const num = 103; | ||
| /*const num = 103; | ||
|
|
||
| function getLastDigit() { | ||
| return num.toString().slice(-1); | ||
| } | ||
|
|
||
| console.log(`The last digit of 42 is ${getLastDigit(42)}`); | ||
| console.log(`The last digit of 105 is ${getLastDigit(105)}`); | ||
| console.log(`The last digit of 806 is ${getLastDigit(806)}`); | ||
| console.log(`The last digit of 806 is ${getLastDigit(806)}`);*/ | ||
|
|
||
| // Now run the code and compare the output to your prediction | ||
| // =============> write the output here | ||
| /* =============> the output: | ||
| The last digit of 42 is 3 | ||
| The last digit of 105 is 3 | ||
| The last digit of 806 is 3*/ | ||
| // Explain why the output is the way it is | ||
| // =============> write your explanation here | ||
| /* =============> The problem is that the function ignores the numbers passed to it, | ||
| it always uses num, which is 103, so it returns 3 every time.*/ | ||
| // Finally, correct the code to fix the problem | ||
| // =============> write your new code here | ||
| /*function getLastDigit() { | ||
| return num.toString().slice(-1); | ||
| } | ||
|
|
||
| console.log(`The last digit of 42 is ${getLastDigit(42)}`); | ||
| console.log(`The last digit of 105 is ${getLastDigit(105)}`); | ||
| console.log(`The last digit of 806 is ${getLastDigit(806)}`);*/ | ||
| // This program should tell the user the last digit of each number. | ||
| // Explain why getLastDigit is not working properly - correct the problem | ||
| // In this case getLastDigit is not working because it's parameter is empty and not declared. | ||
| // Here's the right code: | ||
| function getLastDigit(num) { | ||
| return num.toString().slice(-1); | ||
| } | ||
|
|
||
| console.log(`The last digit of 42 is ${getLastDigit(42)}`); | ||
| console.log(`The last digit of 105 is ${getLastDigit(105)}`); | ||
| console.log(`The last digit of 806 is ${getLastDigit(806)}`); |
|
fatimarouchi 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
|
fatimarouchi 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
|
fatimarouchi 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
|
fatimarouchi 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
|
fatimarouchi 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
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.