Skip to content

Commit 6573f60

Browse files
committed
Create reusable toPounds function with test cases
1 parent 1b5f2cf commit 6573f60

File tree

1 file changed

+10
-5
lines changed

1 file changed

+10
-5
lines changed
Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
1-
// In Sprint-1, there is a program written in interpret/to-pounds.js
1+
// Define a function that converts kilograms to pounds
2+
function toPounds(kg) {
3+
const pounds = kg * 2.20462;
4+
return pounds.toFixed(2); // rounds to 2 decimal places
5+
}
26

3-
// You will need to take this code and turn it into a reusable block of code.
4-
// You will need to declare a function called toPounds with an appropriately named parameter.
5-
6-
// You should call this function a number of times to check it works for different inputs
7+
// Call the function with different inputs to test it
8+
console.log(toPounds(1)); // 2.20
9+
console.log(toPounds(5)); // 11.02
10+
console.log(toPounds(70)); // 154.32
11+
console.log(toPounds(0)); // 0.00

0 commit comments

Comments
 (0)