-
-
Notifications
You must be signed in to change notification settings - Fork 337
London | 26-ITP-Jan | Boualem Larbi Djebbour | sprint 2 | Coursework #1123
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 24 commits
eac1a1b
0a7da43
45b6a43
b594c90
7fbd07f
54e11ce
97bdb37
9dfa312
5fb3b93
b745976
6dcd3ad
98c6c44
49c0e77
f46495a
3a4cd9c
0187c34
d824908
e3e2a6e
d979e47
074eddb
614b5fc
4e87db6
ecbbbef
69ae220
0f84719
3adc57d
1393ad5
132b50e
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,14 +1,28 @@ | ||
| // Predict and explain first... | ||
|
|
||
| // =============> write your prediction here | ||
| // =============> the function when called will throw an error | ||
|
|
||
| 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 | ||
| // =============> the function multiply has no return statement | ||
|
|
||
| // Finally, correct the code to fix the problem | ||
| // =============> write your new code here | ||
| // =============> | ||
| function multiply(a, b) { | ||
| return a * b; // we change the console.log statement with the return statement | ||
| } | ||
|
|
||
| console.log(`The result of multiplying 10 and 32 is ${multiply(10, 32)}`); | ||
|
|
||
| // an extra notice: the purpose of creating a function is to reuse it when needed | ||
| // I've noticed that the parameters are already assigned to values 10 and 32, so I changed the code to the following: | ||
| function multiply(a, b) { | ||
| return console.log( | ||
| `The result of multiplying ` + a + ` and ` + b + ` is ` + a * b | ||
| ); | ||
| } | ||
| multiply(10, 32); | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -3,7 +3,7 @@ | |
| // The BMI calculation divides an adult's weight in kilograms (kg) by their height in metres (m) squared. | ||
|
|
||
| // For example, if you weigh 70kg (around 11 stone) and are 1.73m (around 5 feet 8 inches) tall, you work out your BMI by: | ||
|
|
||
| // | ||
| // squaring your height: 1.73 x 1.73 = 2.99 | ||
| // dividing 70 by 2.99 = 23.41 | ||
| // Your result will be displayed to 1 decimal place, for example 23.4. | ||
|
|
@@ -15,5 +15,6 @@ | |
| // It should return their Body Mass Index to 1 decimal place | ||
|
|
||
| function calculateBMI(weight, height) { | ||
| // return the BMI of someone based off their weight and height | ||
| } | ||
| return (BMI = (weight / (height * height)).toFixed(1)); // return the BMI of someone based off their weight and height | ||
|
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.
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.
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. fixed the statement of the value returned |
||
| } | ||
| console.log(calculateBMI(90, 1.77)); // when calling this function with given someone's weight and height | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -14,3 +14,9 @@ | |
| // 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(wordsSet) { | ||
| let wsSnakeCase = wordsSet.replaceAll(" ", "_"); | ||
| let wsupperSnakeCase = wsSnakeCase.toUpperCase(); | ||
|
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 do you think about this version:
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. I think it could be shortened and embeded in the previous line |
||
| return console.log(wsupperSnakeCase); | ||
| } | ||
|
cjyuan marked this conversation as resolved.
|
||
| upperSnakeCase("i do not know"); // evaluates to: "I_DO_NOT_KNOW" | ||
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.
If there is a need to output the string in a fixed format from different "places" in the program, it would make sense to implement a function do so.
However, what is the purpose of returning the return value of
console.log()? What value do you expectconsole.log()to return?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.
we just actually need the function to pass the output to the next line of code after its destroyed
so we need the function to return what its statement evaluate to
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.
Not sure what you meant by "destroyed".