Skip to content

Commit 71f49ba

Browse files
committed
Practice Reusable Function Syntax
1 parent 1802806 commit 71f49ba

File tree

1 file changed

+37
-0
lines changed

1 file changed

+37
-0
lines changed
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,43 @@
11
// In Sprint-1, there is a program written in interpret/to-pounds.js
22

33
// You will need to take this code and turn it into a reusable block of code.
4+
5+
// need to get car price = let fullPrice
6+
//need get priceOneyear= let priceOneyear
7+
// need take the spaces off the both variables
8+
//need check the diference of the prices
9+
//multiplay the result for 100 to check the percentage
10+
// return the result with template literals
11+
12+
//function needs to be valid with diferents inputs
13+
414
// You will need to declare a function called toPounds with an appropriately named parameter.
515

616
// You should call this function a number of times to check it works for different inputs
17+
18+
19+
// let carPrice = "10,000";
20+
// let priceAfterOneYear = "8,543";
21+
22+
// carPrice = Number(carPrice.replaceAll(",", ""));// 10000
23+
// priceAfterOneYear = Number(priceAfterOneYear.replaceAll(",","")); //8543
24+
25+
// const priceDifference = carPrice - priceAfterOneYear; //1457
26+
// const percentageChange = (priceDifference / carPrice) * 100; //145700
27+
28+
// console.log(`The percentage change is ${percentageChange}`); //14.57
29+
30+
function toPounds(fullPrice, priceOneyear) {
31+
32+
fullPrice = Number(fullPrice.replaceAll(",", ""));
33+
priceOneyear = Number(priceOneyear.replaceAll(",", ""));
34+
35+
const priceDifference = fullPrice - priceOneyear;
36+
37+
const percentageChange = (priceDifference / fullPrice) * 100;
38+
39+
// console.log(`The percentage change is ${percentageChange}`);
40+
return percentageChange;
41+
}
42+
43+
console.log (toPounds( "100,000", "98,000"));

0 commit comments

Comments
 (0)