You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Commit 27843a8
Browse filesBrowse the repository at this point in the historyBrowse files
Copy file name to clipboardExpand all lines: Sprint-3/1-key-errors/0.js
+11-4Lines changed: 11 additions & 4 deletions
Original file line number
Diff line number
Diff line change
@@ -2,9 +2,16 @@
2
2
//This code will throw an error as we haven't passed an argument into str? or str is the function parameter and variable already on line 5 so it may throw an error to declare again as a variable inside the function?
3
3
// call the function capitalise with a string input
4
4
// interpret the error message and figure out why an error is occurring
//SyntaxError: Identifier 'str' has already been declared
11
+
// This code threw an error as "str" has already been defined in the function capitalise(str) so let str is causing the error as it cannot be defined twice.
// In my new code i'm calling the function capitalise(str) in my code "str" is only the parameter and not the variable aswell. In the variable result it will take any argument and using the toUpperCase method itll make a copy of the the letter at index zero as a capital letter so as i passed in "mars" itll return M and store it in the variable result. The method slice will return a copy of the argument from index 1 onwards so "ars" and because it's in a template literal it will join "M" and "ars" together and this is what will get stored in result and by returning result on line 14 i'm asking the function to return what is stored in result so javascript can print it using console.log or i can use it elsewhere as i'm coding.
0 commit comments