Birmingham | 26-ITP-May | Ogbemi Mene | Sprint 2 | coursework #1439
Birmingham | 26-ITP-May | Ogbemi Mene | Sprint 2 | coursework #1439meneogbemi42-bit wants to merge 18 commits into
Conversation
This comment has been minimized.
This comment has been minimized.
1 similar comment
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
1 similar comment
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
1 similar comment
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
|
|
||
| return `${str[0].toUpperCase()}${str.slice(1)}`; | ||
|
|
||
| } |
There was a problem hiding this comment.
Really good explanation of scope and variable declarations here, just wanted to highlight the extra if statement you added. Are you sure it handles the empty string case like you describe?
There was a problem hiding this comment.
this is the best explanation i could come up with.
By checking typeof str !== "string", you are asking: "If the input is anything other than a string, stop processing and just return the input exactly as it is." If you send a string: It skips the if block and proceeds to do the work.
If you send a number: The if condition is true, so it returns the number and ignores the rest of the function.
There was a problem hiding this comment.
So your understanding of what the if statement does (as you've explained here) is good, but that's not what you've said in the comments 🙂 You said:
the if condition i added is to ensure that if an empty string is passed to the function, it will return the empty string instead of throwing an error.
But as you have described, the if condition checks for the data type, not whether the string is empty. How would you check for that?
There was a problem hiding this comment.
yes, the initial statement was not correct, i looked at it critically a saw that this if statement will trow an error, because i did not add this ( | | ) operator, Because of the | | operator, if the string is empty, the function returns str. to handle it i will add || str.length === 0) to the if condition. and this will handle it.
There was a problem hiding this comment.
Please add this second condition then 🙂
There was a problem hiding this comment.
Almost there Ogbemi - just make sure to add this condition and then I'm happy to mark as complete!
|
Really nice explanations Ogbemi! Just a few comments but good work overall. |
Moved the return statement to after the addition operation to ensure the function returns the correct result.
This PR contains debugging, implementation, and interpretation work across multiple coding exercises focusing on function parameters, return values, and string manipulation in JavaScript.