-
-
Notifications
You must be signed in to change notification settings - Fork 240
London | 25-ITP-SEP | Sophia Mohamed | Sprint 2 | coursework/sprint-2 #803
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 9 commits
7312985
113d089
c9700bf
f693105
15d0324
3178e15
a4cfc97
17480c0
d1dfef3
cf13333
33218f8
03351dd
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,20 @@ | ||
| // Predict and explain first... | ||
|
|
||
| // =============> write your prediction here | ||
| // =============> console.log will print the result because log()will write the message to the console. | ||
| // | ||
|
|
||
| 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 | ||
|
|
||
| // =============> When testing the code in Node.js, the output was 320 without the message because it was undefined "The result of multiplying 10 and 32 is undefined". | ||
| //we need to use return to store the result then print it out. | ||
| // Finally, correct the code to fix the problem | ||
| // =============> write your new code here | ||
| // =============> // Corrected Code: | ||
| function multiply(a, b) { | ||
| return a * b; // Use 'return' instead of 'console.log' | ||
| } | ||
| console.log(`The result of multiplying 10 and 32 is ${multiply(10, 32)}`); | ||
|
|
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -4,3 +4,13 @@ | |
| // 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(kg) { | ||
| const pounds = kg * 2.20462; | ||
| return `${pounds.toFixed(2)} lbs`; // returns a string | ||
|
||
| } | ||
|
|
||
| // Test cases | ||
| console.log(toPounds(1)); //the output "2.20 lbs" | ||
| console.log(toPounds(5)); //the output is "11.02 lbs" | ||
| console.log(toPounds(10)); //the output is "22.05 lbs" | ||
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.
Both of these function calls output
123in the console, but internally in the program,the number
123and the string"123"are stored and treated differently.What type of value do you expect your function to return? A number or a string?
Does your function return the type of value you expect?
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.
I expect the function to return a number, because a BMI is a numeric value. Yes, I tested the function, and it comes as a number.
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.
How did you test if its return value is a number and not a string?
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.
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.
That's not a proper way to check the type of a value.
Can you ask AI (and then verify if needed) how to determine the type of a value in JS?
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.
Thank you so much, that was really helpful. I used (type of )and it showed me that my output was a string, and I changed it to a number