generated from CodeYourFuture/Module-Template
-
-
Notifications
You must be signed in to change notification settings - Fork 240
Manchester | 25-ITP-Sep | Khalidbih | Sprint 2 | coursework/sprint-2 #854
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
khalidbih
wants to merge
20
commits into
CodeYourFuture:main
Choose a base branch
from
khalidbih: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 16 commits
Commits
Show all changes
20 commits
Select commit
Hold shift + click to select a range
07075e1
I fixed the error and wrote a new code, it runs perfectly
khalidbih 7291d85
I fixed the error and wrote a new code, it runs perfectly
khalidbih e838340
Fix convertToPercentage function; now returns correct 50% output
khalidbih 9bcb86b
I had to delete the broken code
khalidbih b4435a7
Corrected square function; prints 9 for input 3
khalidbih ccf9b9b
Fixed multiply function to return correct output
khalidbih 3ae35f7
Updated variable names
khalidbih f5a273a
I fixed errors and its able to run the code
khalidbih 3960c56
I changed the console.log
khalidbih e7be3d3
I fixed the return
khalidbih 3557fef
exercise completed
khalidbih 41416d5
I used toUpperSnakeCase as the function name
khalidbih 770c94a
I added reusable toPounds function
khalidbih f425e8a
This exercise complete
khalidbih b953519
I Fixed the code to get parts of filePath; runs correctly
khalidbih f976015
format-time.js in Sprint-2
khalidbih 2579613
I Removed unrelated Sprint-1 files from Sprint-2 PR
khalidbih 7f0b538
I Removed unrelated Sprint-1 files from Sprint-2 PR
khalidbih e679e68
I Removed unrelated Sprint-1 files from Sprint-2 PR
khalidbih 34ea901
I removed Sprint-1 files from Sprint-2 PR
khalidbih 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,2 +1,2 @@ | ||
| This is just an instruction for the first activity - but it is just for human consumption | ||
| We don't want the computer to run these 2 lines - how can we solve this problem? | ||
| // This is just an instruction for the first activity - but it is just for human consumption | ||
| // We don't want the computer to run these 2 lines - how can we solve this problem? |
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,2 +1,2 @@ | ||
| const 12HourClockTime = "20:53"; | ||
| const 24hourClockTime = "08:53"; | ||
| const twelveHourClockTime = "20:53"; | ||
| const twentyFourHourClockTime = "08:53"; |
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 |
|---|---|---|
| @@ -1,13 +1,21 @@ | ||
| // Predict and explain first... | ||
| // =============> write your prediction here | ||
| //I think it will give an error because we have `str` twice in line 10 we should only have return without `str` | ||
|
|
||
| // 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; | ||
| } | ||
| // function capitalise(str) { | ||
| // let str = `${str[0].toUpperCase()}${str.slice(1)}`; | ||
| // return str; | ||
| // } | ||
|
|
||
| // =============> write your explanation here | ||
| // =============> write your new code here | ||
| // The error happened because 'str' was declared twice, once as a parameter and once with 'let' inside the function. | ||
| // Also, when calling the function, using a word without quotes caused a ReferenceError. | ||
| // After removing the duplicate declaration and passing a string with quotes, the function works correctly, | ||
| // =============> write your new code here | ||
| function capitalise(str) { | ||
| return `${str[0].toUpperCase()}${str.slice(1)}`; | ||
| } | ||
| console.log(capitalise("Hard")); |
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 | ||
|
|
||
| // Try playing computer with the example to work out what is going on | ||
| // =============> write your prediction here | ||
|
|
||
| function convertToPercentage(decimalNumber) { | ||
| const decimalNumber = 0.5; | ||
| const percentage = `${decimalNumber * 100}%`; | ||
| // the error occur because the decimalNumber has already been declared. | ||
|
|
||
| // Try playing computer with the example to work out what is going on | ||
|
|
||
| return percentage; | ||
| } | ||
|
|
||
| console.log(decimalNumber); | ||
|
|
||
| // =============> write your explanation here | ||
|
|
||
| // I tried to run the code it gives me SyntaxError,that the decimalNumber has already been declared, we can see in the parameter already has name decimalNumber. | ||
| // thats why declaring it again inside the function, causes an errors. | ||
|
|
||
| // 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
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,17 @@ | ||
| // Predict and explain first... | ||
|
|
||
| // =============> write your prediction here | ||
|
|
||
| function multiply(a, b) { | ||
| console.log(a * b); | ||
| } | ||
|
|
||
| console.log(`The result of multiplying 10 and 32 is ${multiply(10, 32)}`); | ||
| // in console.log we should just write (multiply(10,32) because writing in plain english will give us an error, | ||
| // and it won't give the output. | ||
|
|
||
| // =============> write your explanation here | ||
| // the code was broken because the console.log was inside the function it not a function,by using the return it gives the outupt | ||
|
|
||
|
|
||
| // Finally, correct the code to fix the problem | ||
| // =============> write your new code here | ||
| function multiply(a, b) { | ||
| return (a * b) | ||
| } | ||
|
|
||
| console.log(multiply(10, 32)); |
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,16 @@ | ||
| // Predict and explain first... | ||
| // =============> write your prediction here | ||
| // The return statement is not in the right place, so the function doesn’t return the value. | ||
|
|
||
| function sum(a, b) { | ||
| return; | ||
| a + b; | ||
| } | ||
| // =============> write your explanation here | ||
|
|
||
| console.log(`The sum of 10 and 32 is ${sum(10, 32)}`); | ||
| // The return statement is stopping the function too early, so it doesn’t return a + b. | ||
|
|
||
| // =============> write your explanation here | ||
| // 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)}`); |
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,27 @@ | |
| // 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 | ||
| 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}`; | ||
| } | ||
|
Comment on lines
+7
to
+25
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. The indentation of the code is a bit off. Suggestion: You can use this VSCode feature to auto indent JS code. |
||
| console.log (toPounds("399p")); | ||
| console.log (toPounds("400p")); | ||
| console.log (toPounds("243p")); | ||
| console.log (toPounds("9876p")); | ||
| console.log (toPounds("18p")); | ||
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.
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.
Did you notice the variables
roundedandBMIare rendered in different colors?Many IDEs and viewers that support syntax highlighting (including GitHub) display identifiers in different formats and colors.
Can you look up the naming conventions in JavaScript? In particular,
Then, update the variable names according to those conventions.
On separate note, it is a good practice to declare a "variable" using
constinstead ofletwhen the variable is not going to be reassigned a value.