-
-
Notifications
You must be signed in to change notification settings - Fork 546
London | 26-ITP-SEPT | Carol Nassuna | Sprint 3 | Coursework #1606
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
f97b348
620e7c7
3365fc9
ed4e7a2
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,23 @@ | ||
| // Predict and explain first... | ||
| // =============> write your prediction here | ||
| // It would fail at line 2 with either syntax or reference errors =============> write your prediction here | ||
|
|
||
| // call the function capitalise with a string input | ||
| // interpret the error message and figure out why an error is occurring | ||
| // interpret the error message and figure out why an error is occurring. | ||
|
|
||
| function capitalise(str) { | ||
| let str = `${str[0].toUpperCase()}${str.slice(1)}`; | ||
| return str; | ||
| } | ||
| console.log(capitalise("beautiful")); | ||
|
|
||
| // write your explanation here: | ||
| // Syntax Error: Identifier 'Str' has been already been declared/assigned | ||
| // The error means Str had already been identified in the function capitalise(str). Let str is assigning a second value which is causing that error message | ||
|
|
||
| // =============> write your explanation here | ||
| // =============> write your new code here | ||
|
|
||
| function capitalise(str) { | ||
| str = `${str[0].toUpperCase()}${str.slice(1)}`; | ||
| return str; | ||
| } | ||
| console.log(capitalise("beautiful")); | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,7 +1,8 @@ | ||
| // Predict and explain first... | ||
|
|
||
| // Why will an error occur when this program runs? | ||
| // =============> write your prediction here | ||
| // write your prediction here | ||
| // This is because the variable name for the parameter and the cont is the same | ||
|
|
||
| // Try playing computer with the example to work out what is going on | ||
|
|
||
|
|
@@ -14,7 +15,18 @@ function convertToPercentage(decimalNumber) { | |
|
|
||
| console.log(decimalNumber); | ||
|
|
||
| // =============> write your explanation here | ||
| //=============> write your explanation here | ||
| //The decimalNumber is declared twice as a result, calling convertToPercentage function and passing a value gets assigned to parameter decimalNumber | ||
| //So i had to move it outside of the function scope to remove restrictions | ||
|
|
||
| // Finally, correct the code to fix the problem | ||
| // Finally, correct the code to fix the problem. | ||
| // =============> write your new code here | ||
|
|
||
| function convertToPercentage(decimalNumber) { | ||
| const percentage = `${decimalNumber * 100}%`; | ||
|
|
||
| return percentage; | ||
| } | ||
| const decimalNumber = 0.5; | ||
|
|
||
| console.log(decimalNumber); | ||
|
Contributor
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. After you comment out the original code, this line prints |
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,20 +1,25 @@ | ||
|
|
||
| // 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 | ||
| // Unidentified function error due to a random number =============> write your prediction of the error here | ||
|
|
||
| function square(3) { | ||
| return num * num; | ||
| } | ||
| //function square(num) { | ||
| //return square = num * num; | ||
| //} | ||
|
|
||
| // =============> write the error message here | ||
| // Syntax errorError Unexpected number.=============> write the error message here | ||
|
|
||
| // =============> explain this error message here | ||
| // Means Function identifier should be a name not a number =============> explain this error message here. | ||
|
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. Whats the difference between function identifier and parameter? 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. I think you're confused between the function identifiers, parameters and arguments. please review the following and update the explanation.
Contributor
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. That's right now, and the fix on line 23 too. Well done for sticking with this one. |
||
| // Whats the difference between function identifier and parameter? | ||
| // The parameter of a function must be name not number. So Parsing number 3 into the parameter would throw an error. | ||
| // Changing number 3 to 'num' as a placeholder fixes the error | ||
|
|
||
| // Finally, correct the code to fix the problem | ||
|
|
||
| // =============> write your new code here | ||
|
|
||
|
|
||
| function square(num) { | ||
| return num * num; | ||
| } | ||
| console.log(square(3)); | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,6 +1,6 @@ | ||
| // Predict and explain first... | ||
| // Predict and explain first.... | ||
|
|
||
| // =============> write your prediction here | ||
| // Code will fail because a , b are not declared values or double function values=============> write your prediction here | ||
|
|
||
| function multiply(a, b) { | ||
| console.log(a * b); | ||
|
|
@@ -9,6 +9,14 @@ function multiply(a, b) { | |
| console.log(`The result of multiplying 10 and 32 is ${multiply(10, 32)}`); | ||
|
|
||
| // =============> write your explanation here | ||
| //The 2nd console log returned value value is undefined. I have added a return function to output the multiply value. | ||
|
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. why was the value returned by the function is undefined? |
||
| //The value returned by the function was undefined because the value hasn't been stored anywhere, and there's no return to return the value to the function call. | ||
|
|
||
| // Finally, correct the code to fix the problem | ||
| //Finally, correct the code to fix the problem | ||
| // =============> write your new code here | ||
| function multiply(a, b) { | ||
| console.log(a * b); | ||
| return a * b; | ||
| } | ||
|
|
||
| console.log(`The result of multiplying 10 and 32 is ${multiply(10, 32)}`); | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -17,3 +17,12 @@ | |
| function calculateBMI(weight, height) { | ||
| // return the BMI of someone based off their weight and height | ||
| } | ||
|
|
||
| function calculateBMI(weight, height) { | ||
|
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. pleaser review the formula for calculating the BMI in the description above again. |
||
| //return (weight / height).toFixed(1); - 1st attempt | ||
| //return (weight / (height * height)).toString().slice(0, 4); - 2nd attempt | ||
| return "${(weight / (height * height)).toFixed(1)}"; | ||
| } | ||
|
|
||
| console.log(`the bmi of 70 and 2.99 is ${calculateBMI(70, 2.99)}`); | ||
|
Contributor
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 function needs the height, not the height squared. Line 7 shows the person is |
||
| console.log(`the bmi of 90 and 1.96 is ${calculateBMI(90, 1.96)}`); | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -14,3 +14,16 @@ | |
| // 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 toUpperSnakeCase(text) { | ||
| // return text.trim().replace(/\s+/g, "_").toUpperCase(); - first attempt that inserted underscore | ||
| return text.toUpperCase().replaceAll(" ", "_"); | ||
| } | ||
|
|
||
| const text = toUpperSnakeCase("Hello there"); | ||
| console.log(text); | ||
|
|
||
| // Trim and regex pattern was the only saving grace I came across to resolve the underscore issue I had spent hours researching. | ||
| // I have however now modified and replaced the pattern for easy understanding with AI's help | ||
|
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. I appreciate your transparency. Using AI as a tool for research and to help clarify concepts you're struggling with is absolutely fine. You can find further guidance on the appropriate use of AI in the document below. |
||
| // CodeYourFuture AI Usage Guide reviewed again | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -22,17 +22,22 @@ function formatTimeDisplay(seconds) { | |
|
|
||
| // a) When formatTimeDisplay is called how many times will pad be called? | ||
| // =============> write your answer here | ||
| // Pad will be called 3 times because of the 3 arguments | ||
|
|
||
| // Call formatTimeDisplay with an input of 61, now answer the following: | ||
|
|
||
| // b) What is the value assigned to num when pad is called for the first time? | ||
| // =============> write your answer here | ||
| 0; | ||
|
|
||
| // c) What is the return value of pad when it is called for the first time? | ||
| // =============> write your answer here | ||
| //00; | ||
|
|
||
| // d) What is the value assigned to num when pad is called for the last time in this program? Explain your answer | ||
| // =============> write your answer here | ||
| // The value is 1 because the last pad argument is remainingSeconds. So 61 as the given seconds - remaining seconds = 1 | ||
|
|
||
| // e) What is the return value of pad when it is called for the last time in this program? Explain your answer | ||
| // =============> write your answer here | ||
| // The answer is 01 because of the final output for formatTimeDisplay(61) is 00:01:01. The assigned value of 1 with the length of 1, the numString = "0" + numString becomes 1 | ||
|
Contributor
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 answer |
||
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.
Your new code here is right, but it never runs. Try it: right click the
1-key-errorsfolder in VS Code, choose Open in Integrated Terminal, and runnode 0.js. You'll see the SyntaxError from line 8. The original code on lines 7 to 11 still runs first, and JavaScript stops at the first error.Select lines 7 to 11 and press
Ctrl + /(Cmd + /on a Mac) to turn them into comments. Runnode 0.jsagain and you should seeBeautiful.Do the same in
1.jsfor lines 9 to 16.