-
-
Notifications
You must be signed in to change notification settings - Fork 241
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 2 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 |
|---|---|---|
|
|
@@ -6,14 +6,11 @@ | |
| // 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; | ||
| const pounds = kg * 2.20462; | ||
| return `${pounds.toFixed(2)} lbs`; // returns a string | ||
|
||
| } | ||
| console.log(toPounds(1)); | ||
| console.log(toPounds(5)); | ||
| console.log(toPounds(10)); | ||
| // if I want to round the result to 2 decimal places I can use toFixed(2) | ||
| console.log(toPounds(1).toFixed(2)); | ||
| console.log(toPounds(5).toFixed(2)); | ||
| console.log(toPounds(10).toFixed(2)); | ||
|
|
||
| // 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