-
-
Notifications
You must be signed in to change notification settings - Fork 337
London | 26-ITP-Jan | Divine Mankrado | Sprint 2 | Sprint-2 #1169
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 11 commits
0f63b87
0f18c37
b286998
c35ac0c
f5b1cd8
ae15e29
53dfb73
601f051
6cb971f
4f0ce61
f6eafd0
925895f
8416a21
6f10d48
d2d31ba
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,18 @@ | ||
| // Predict and explain first... | ||
| // =============> write your prediction here | ||
| // =============> The error will be that the variable str is being redefined within the function. It was already defined when it was passed as an arguement. | ||
|
|
||
| // call the function capitalise with a string input | ||
| capitalise("hello world"); | ||
| // interpret the error message and figure out why an error is occurring | ||
| // Error message: SyntaxError: Identifier 'str' has already been declared. The error is because the variable str has already been declared. | ||
|
|
||
| function capitalise(str) { | ||
| let str = `${str[0].toUpperCase()}${str.slice(1)}`; | ||
| return str; | ||
| } | ||
|
|
||
| // =============> write your explanation here | ||
| // =============> write your new code here | ||
| // =============> I've given the variable a new name, newStr, to avoid redclaring the variable. | ||
| // =============> function capitalise(str) { | ||
| // let newStr = `${str[0].toUpperCase()}${str.slice(1)}`; | ||
| // return newStr; | ||
| //} | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,20 +1,19 @@ | ||
|
|
||
| // 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 error will be a syntax error. A number is not a valid variable name - variable names cannot start with a number. | ||
|
|
||
| function square(3) { | ||
| return num * num; | ||
| } | ||
|
|
||
| // =============> write the error message here | ||
| // =============> write the error message here: SyntaxError: Unexpected number. The error is because the variable name cannot start with a number. | ||
|
|
||
| // =============> explain this error message here | ||
| // =============> explain this error message here: You cannot begin a variable name with a number | ||
|
|
||
| // Finally, correct the code to fix the problem | ||
|
|
||
| // =============> write your new code here | ||
|
|
||
|
|
||
| // =============> write your new code here: | ||
| // function square(num) { | ||
| // return num * num; | ||
| // } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,14 +1,17 @@ | ||
| // Predict and explain first... | ||
|
|
||
| // =============> write your prediction here | ||
| // =============> write your prediction here: The function does not return any value so instead of 320 being printed, undefined will be printed instead. | ||
|
|
||
| function multiply(a, b) { | ||
| console.log(a * b); | ||
| } | ||
|
|
||
| console.log(`The result of multiplying 10 and 32 is ${multiply(10, 32)}`); | ||
|
|
||
| // =============> write your explanation here | ||
| // =============> write your explanation here: It is a logic error as it prints out an unexpected value, undefined. | ||
|
|
||
| // Finally, correct the code to fix the problem | ||
| // =============> write your new code here | ||
| //function multiply(a, b) { | ||
| // return a * b; | ||
| //} |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -16,4 +16,5 @@ | |
|
|
||
| function calculateBMI(weight, height) { | ||
| // return the BMI of someone based off their weight and height | ||
| return (weight/(height**2)).toFixed(1); | ||
| } | ||
|
Comment on lines
17
to
21
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. Is there a better way to write the code to make it more readable? Also, look into the bmi calculation to make sure the right calculation is done within your code.
Author
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. Thanks for the comment! I've updated the code |
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -14,3 +14,7 @@ | |
| // 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 upperSnakeCase(str){ | ||
| return str.toUpperCase().split(" ").join("_"); | ||
| } | ||
|
Comment on lines
+18
to
+20
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. Good way to handle some edge cases from the passed argument |
||
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.
This is a way to do it. Is there a better way to do it in one line without redeclaring a variable within the function?
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.
Yes. This is the other way to do it. Should I update my code with this?
function capitalise(str) {
return str[0].toUpperCase() + str.slice(1);
}