-
-
Notifications
You must be signed in to change notification settings - Fork 387
Cape Town | 25-ITP-May | Asanda Dunn | Sprint 2 | Coursework/sprint2 #1418
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
c12f358
de229c5
30efd9d
3e834b4
ccc134b
62c7888
3f8ce08
3e2c324
c697a4d
4fd9db6
22907b2
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,27 @@ | ||
| // Predict and explain first... | ||
| // =============> write your prediction here | ||
| // I don't think this will work because str is already an argument in the capitalise function | ||
| // so declaring it again is incorrect. Another thing is the variable str is being declared but the value assigned to | ||
| // it basically uses the str variable to interpolate the string | ||
|
|
||
| // call the function capitalise with a string input | ||
| // 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; | ||
| } | ||
|
|
||
| // =============> write your explanation here | ||
| // =============> write your explanation here// | ||
| // SyntaxError: Identifier 'str' has already been declared | ||
| // this is happening because the str variable already exist as an argument in this function | ||
| // =============> write your new code here | ||
|
|
||
| function capitalize(str){ | ||
| let car = `${str[0].toUpperCase()}${str.slice(1)}`; | ||
| return car; | ||
| } | ||
| capitalize("hello") | ||
| console.log(capitalize("hello")) |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,14 +1,21 @@ | ||
| // Predict and explain first... | ||
|
|
||
| // =============> write your prediction here | ||
|
|
||
| // This function is not returning anything | ||
| 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 | ||
|
|
||
| // This function is not returning anything. It does multiply the assigned values of a,b but it does not return the String with the | ||
| // as required on line 9 | ||
| // Finally, correct the code to fix the problem | ||
| // =============> write your new code here | ||
|
|
||
| function multiply(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 |
|---|---|---|
|
|
@@ -15,5 +15,8 @@ | |
| // It should return their Body Mass Index to 1 decimal place | ||
|
|
||
| function calculateBMI(weight, height) { | ||
| let bmi = weight/(height *height) | ||
| return `${bmi.toFixed(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. What type of value do you expect your function to return? A number or a string? Different types of values may appear identical in the console output, but they are represented and treated differently in the program. For example, console.log(123); // Output 123
console.log("123"); // Output 123
// Treated differently in the program
let sum1 = 123 + 100; // Evaluate to 223 -- a number
let sum 2 = "123" + 100; // Evaluate to "123100" -- a string.Note: return `${bmi.toFixed(1)}`;is the same as return bmi.toFixed(1); |
||
| // return the BMI of someone based off their weight and height | ||
| } | ||
| } | ||
| console.log(calculateBMI(80 , 1.73)) | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -14,3 +14,8 @@ | |
| // 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) { | ||
|
Comment on lines
+17
to
+18
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. Could you look up the naming conventions in JavaScript? In particulars,
Then, update the function name according to those conventions. |
||
| return `${str.toUpperCase().replaceAll(" ", "_")}`; | ||
|
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. Use of string template is no needed. |
||
| } | ||
| console.log(UpperSnakeCase("hello world in javascript")); | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -4,3 +4,27 @@ | |
| // You will need to declare a function called toPounds with an appropriately named parameter. | ||
|
|
||
| // You should call this function a number of times to check it works for different inputs | ||
| function toPounds(penceString){ | ||
|
|
||
| const penceStringWithoutTrailingP = penceString.substring( | ||
| 0, | ||
| penceString.length - 1 | ||
| ); | ||
|
|
||
| const paddedPenceNumberString = penceStringWithoutTrailingP.padStart( | ||
| 3, | ||
| "0" | ||
| ); | ||
| const pounds = paddedPenceNumberString.substring( | ||
| 0, | ||
| paddedPenceNumberString.length - 2 | ||
| ); | ||
|
|
||
| const pence = paddedPenceNumberString | ||
| .substring(paddedPenceNumberString.length - 2) | ||
| .padEnd(2, "0"); | ||
|
|
||
| const result = `£${pounds}.${pence}`; | ||
| return result | ||
|
Comment on lines
+27
to
+28
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. Code is not properly formatted. Have you installed the prettier VSCode extension and enabled "Format on save/paste" on VSCode, |
||
| } | ||
| console.log(toPounds("399p")) | ||
|
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. Why not complete the implementation of the |
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.
return a * b;would be enough.The general syntax of the return statement is:
And the value of
expressionis returned.