generated from CodeYourFuture/Module-Template
-
-
Notifications
You must be signed in to change notification settings - Fork 195
LONDON | ITP_MAY | Mirabel Adom | Module-Structuring-and-Testing-Data | Sprint-2 #655
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
Mirabel-Adom
wants to merge
1
commit into
CodeYourFuture:main
Choose a base branch
from
Mirabel-Adom:coursework/sprint-2
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
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,17 @@ | ||
// Predict and explain first... | ||
// =============> write your prediction here | ||
// The code will produce an error. | ||
|
||
// call the function capitalise with a string input | ||
// interpret the error message and figure out why an error is occurring | ||
//The error message indicates that 'str' has already been declared: function capitalise(str) and let str | ||
|
||
function capitalise(str) { | ||
let str = `${str[0].toUpperCase()}${str.slice(1)}`; | ||
return str; | ||
} | ||
|
||
// =============> write your explanation here | ||
// =============> write your new code here | ||
// =============> The error message indicates that 'str' has already been declared. | ||
// =============> | ||
function capitalise(str) { | ||
let capitalisedStr = `${str[0].toUpperCase()}${str.slice(1)}`; | ||
return capitalisedStr; | ||
} |
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,25 @@ | ||
// Predict and explain first... | ||
|
||
// Why will an error occur when this program runs? | ||
// =============> write your prediction here | ||
// =============> An error code will occur because 'decimalNumber' has already been declared. | ||
|
||
// Try playing computer with the example to work out what is going on | ||
|
||
function convertToPercentage(decimalNumber) { | ||
const decimalNumber = 0.5; | ||
const percentage = `${decimalNumber * 100}%`; | ||
// function convertToPercentage(decimalNumber) { | ||
// const decimalNumber = 0.5; | ||
// const percentage = `${decimalNumber * 100}%`; | ||
|
||
return percentage; | ||
} | ||
// return percentage; | ||
// } | ||
|
||
console.log(decimalNumber); | ||
// console.log(decimalNumber); | ||
|
||
// =============> write your explanation here | ||
// =============> The original code didn't work because the variable name was reused and the value was printed outside the function. | ||
|
||
// 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)); |
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,20 @@ | ||
|
||
// 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 | ||
// =============> The code will produce an error because the function parameters must be variable names, instead of a value - in this case the error has occured because of 3. | ||
|
||
function square(3) { | ||
return num * num; | ||
} | ||
// function square(3) { | ||
// return num * num; | ||
// } | ||
|
||
// =============> write the error message here | ||
// =============> SyntaxError: Unexpected number | ||
|
||
// =============> explain this error message here | ||
// =============> The error message suggests that JavaScript requires a variable name rather than a number. | ||
|
||
// Finally, correct the code to fix the problem | ||
|
||
// =============> write your new code here | ||
|
||
|
||
// =============> | ||
function square(num) { | ||
return num * num; | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,3 +4,47 @@ | |
// You will need to declare a function called toPounds with an appropriately named parameter. | ||
|
||
// You should call this function a number of times to check it works for different inputs | ||
|
||
const penceString = "399p"; | ||
|
||
const penceStringWithoutTrailingP = penceString.substring( | ||
0, | ||
penceString.length - 1 | ||
); | ||
|
||
const paddedPenceNumberString = penceStringWithoutTrailingP.padStart(3, "0"); | ||
const pounds = paddedPenceNumberString.substring( | ||
0, | ||
paddedPenceNumberString.length - 2 | ||
); | ||
|
||
const pence = paddedPenceNumberString | ||
.substring(paddedPenceNumberString.length - 2) | ||
.padEnd(2, "0"); | ||
|
||
console.log(`£${pounds}.${pence}`); | ||
Comment on lines
+10
to
+25
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. Are these code still needed? |
||
|
||
//Refactored code | ||
function toPounds(penceString) { | ||
const penceStringWithoutTrailingP = penceString.substring( | ||
0, | ||
penceString.length - 1 | ||
); | ||
|
||
const paddedPenceNumberString = penceStringWithoutTrailingP.padStart(3, "0"); | ||
|
||
const pounds = paddedPenceNumberString.substring( | ||
0, | ||
paddedPenceNumberString.length - 2 | ||
); | ||
|
||
const pence = paddedPenceNumberString | ||
.substring(paddedPenceNumberString.length - 2) | ||
.padEnd(2, "0"); | ||
|
||
return `£${pounds}.${pence}`; | ||
} | ||
|
||
// console.log(toPounds("399p")); // £3.99 | ||
// console.log(toPounds("99p")); // £0.99 | ||
// console.log(toPounds("5p")); // £0.05 |
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.
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 type of value do you expect the function to return? A number or a string?
Does your function return the type of value you expect it to return?