-
-
Notifications
You must be signed in to change notification settings - Fork 330
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
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") |
|
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. 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. |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,13 +1,20 @@ | ||
| // 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; | ||
| 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 because of the ; this because the function doesn't return anything. | ||
|
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. You mentioned the function exits specifically because of the ; What happens if you delete that ; after return, but leave a + b on the next line? Give it a try! (Hint: Look up Automatic Semicolon Insertion (ASI) in JavaScript to see why the line break itself. Any code below a return statement becomes "unreachable code".) |
||
| // 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)}`); | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -16,4 +16,13 @@ | |
|
|
||
| function calculateBMI(weight, height) { | ||
| // return the BMI of someone based off their weight and height | ||
| } | ||
| console.log("weight", weight); | ||
| console.log("height",height); | ||
|
Comment on lines
+19
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. These logs are awesome for testing and debugging! However, for a clean final submission, what should we do with them? |
||
|
|
||
| const heightSquared = (height * height).toFixed(2); | ||
|
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. Great job breaking the steps down! Quick question on this line: do you know what data type .toFixed() returns? Think about how that might affect the division operation on the next line. Is it better to round values in the middle of an equation, or only at the very end? |
||
| console.log("heightSquared",heightSquared); | ||
| const BMI = (weight / heightSquared).toFixed(2); | ||
|
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. Take another quick look at the task instructions regarding the decimal places. Are we returning the correct amount here? Also, keep in mind that .toFixed() will return a string. If the function is expected to return a Number, how could you convert it? |
||
| console.log("BMI",BMI) | ||
| return BMI; | ||
| } | ||
| console.log("calculateBMI",calculateBMI(70, 1.73)) | ||
|
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,10 @@ | |
| // 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){ | ||
| const result = str.split(" ").join("_").toUpperCase(); //take str, and turn it into an array and then turn it back into a string with underscores then upper case it. | ||
| console.log("result",result); | ||
|
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. Make sure to clean up your debugging logs before your final submission! |
||
| } | ||
|
Comment on lines
+18
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. Your string manipulation logic is perfect! However, try running this exact code. You'll notice the final |
||
|
|
||
| console.log(makeUpperCaseSnakeCase("hello there")); | ||
|
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 mentioned 'argument', but the correct term for what goes inside the parentheses when you create a function is a Parameter. So, in this case it's a parameter.