-
-
Notifications
You must be signed in to change notification settings - Fork 336
Manchester | 26-ITP-Jan | Liban Jama | Sprint 2 | Structuring and Testing Data #1101
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
base: main
Are you sure you want to change the base?
Changes from all commits
bd4fe1f
95e7076
7bc25aa
2ef3cb2
ca40d0c
9bca312
a858eb9
fc46f16
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,13 +1,20 @@ | ||
| // Predict and explain first... | ||
| // =============> write your prediction here | ||
|
|
||
| // it will take a string and turn the first letter into a capital. | ||
| // call the function capitalise with a string input | ||
| // interpret the error message and figure out why an error is occurring | ||
|
|
||
| // SyntaxError: Identifier 'str' has already been declared - str cannot be used twice as a variable name. | ||
| function capitalise(str) { | ||
| let str = `${str[0].toUpperCase()}${str.slice(1)}`; | ||
| return str; | ||
| } | ||
|
|
||
| // =============> write your explanation here | ||
| // i've changed the variable name from str to result. This corrected the error and return result. | ||
| // =============> write your new code here | ||
| function capitalise(str) { | ||
| let result = `${str[0].toUpperCase()}${str.slice(1)}`; | ||
| console.log("result",result); | ||
| return result; | ||
| } | ||
| capitalise("pear") |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,13 +1,22 @@ | ||
| // Predict and explain first... | ||
| // =============> write your prediction here | ||
|
|
||
| // This appears correct. The function has been defined and called sum, a is 10 and b is 32 so we should get 42. | ||
| 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 sum of 10 and 32 is undefined. On line five the function has been exited early because of the return; | ||
| // a + b need to be on the same line as the return otherwise you'd get "unreachable code detected" error. | ||
|
|
||
| // Finally, correct the code to fix the problem | ||
|
|
||
| // =============> write your new code here | ||
|
|
||
| function sum(a, b) { | ||
| return a + b; | ||
| } |
|
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. This works great! Since the instructions pointed you toward the MDN String documentation, take a peek at the .replaceAll() method. How could you use that to achieve the same result without needing to convert the string into an array first? |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -14,3 +14,9 @@ | |
| // You will need to come up with an appropriate name for the function | ||
| // Use the MDN string documentation to help you find a solution | ||
| // This might help https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/toUpperCase | ||
|
|
||
| function makeUpperCaseSnakeCase(str){ | ||
| // .replaceAll takes the empty space and replaces it with underscore and .toUpperCase makes all the letters capitals. | ||
| const result = str.replaceAll(" ", "_").toUpperCase(); | ||
| return result; | ||
| } | ||
|
Comment on lines
+18
to
+22
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. Your string manipulation logic is perfect! However, try running this exact code. You'll notice the final |
||
|
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. Can you please read the instruction in the assessment? You need to follow the instructions and make use of the starter code stated. |
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.
You've made a correction to the code but I can't see your explanation.
If you could kindly explain what's wrong with the original code and the what you did to correct it.