Skip to content

Commit 719afc9

Browse files
author
Yonas Gebre
committed
practice until to-pounds
1 parent b31a586 commit 719afc9

3 files changed

Lines changed: 30 additions & 11 deletions

File tree

Sprint-1/3-mandatory-interpret/1-percentage-change.js

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ let carPrice = "10,000";
22
let priceAfterOneYear = "8,543";
33

44
carPrice = Number(carPrice.replaceAll(",", ""));
5-
priceAfterOneYear = Number(priceAfterOneYear.replaceAll("," ""));
5+
priceAfterOneYear = Number(priceAfterOneYear.replaceAll(",", ""));
66

77
const priceDifference = carPrice - priceAfterOneYear;
88
const percentageChange = (priceDifference / carPrice) * 100;
@@ -12,11 +12,21 @@ console.log(`The percentage change is ${percentageChange}`);
1212
// Read the code and then answer the questions below
1313

1414
// a) How many function calls are there in this file? Write down all the lines where a function call is made
15-
15+
// There are 4 fucntion calls
16+
//Number(carPrice.replaceAll(",", "")); 2 calls Function Number and Function replaceAll
17+
//Number(priceAfterOneYear.replaceAll(",""")); 2 calls Function Number and Function replaceAll
1618
// b) Run the code and identify the line where the error is coming from - why is this error occurring? How can you fix this problem?
17-
19+
// line 5 priceAfterOneYear = Number(priceAfterOneYear.replaceAll("," ""));
20+
// ^^^SyntaxError: missing ) after argument list
21+
// add semicolon after te the first argument in the replaceAll method to fix the error
1822
// c) Identify all the lines that are variable reassignment statements
23+
//line 4 to varaible carprice //carPrice = Number(carPrice.replaceAll(",", ""));
24+
//line 5 to variable priceAfterOneYear //priceAfterOneYear = Number(priceAfterOneYear.replaceAll("," ""));
1925

2026
// d) Identify all the lines that are variable declarations
21-
27+
//line 1 to variable carPrice //let carPrice = "10,000";
28+
//line 2 to variable priceAfterOneYear //let priceAfterOneYear = "8,543";
29+
//line 7 to variable priceDifference //const priceDifference = carPrice - priceAfterOneYear;
30+
//line 8 to variable percentageChange //const percentageChange = (priceDifference / carPrice) * 100;
2231
// e) Describe what the expression Number(carPrice.replaceAll(",","")) is doing - what is the purpose of this expression?
32+
// it replace all the commas with empty string and convert the string to number.

Sprint-1/3-mandatory-interpret/2-time-format.js

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
const movieLength = 8784; // length of movie in seconds
1+
const movieLength = 60; // length of movie in seconds
22

33
const remainingSeconds = movieLength % 60;
44
const totalMinutes = (movieLength - remainingSeconds) / 60;
@@ -12,14 +12,22 @@ console.log(result);
1212
// For the piece of code above, read the code and then answer the following questions
1313

1414
// a) How many variable declarations are there in this program?
15+
// There are 6 variable declarations.
1516

1617
// b) How many function calls are there?
18+
// one function call in the program, which is console.log(result);
1719

1820
// c) Using documentation, explain what the expression movieLength % 60 represents
1921
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Arithmetic_Operators
20-
22+
//modulo operator returns left over after division. the expession movieLength % 60 returns the
23+
// remaining seconds after dividing the movieLength by 60. In this case, it returns 24, which is the remaining seconds after dividing 8784 by 60.
2124
// d) Interpret line 4, what does the expression assigned to totalMinutes mean?
22-
25+
// the expression covert the movieLength from seconds to minutes.
26+
// it subtracts the remaining seconds from the movieLength and divides the result by 60 to get the total minutes. In this case, it returns 146, which is the total minutes of the movie length.
2327
// e) What do you think the variable result represents? Can you think of a better name for this variable?
24-
28+
// the total length of movie in hours,minutes and seconds.
29+
// a better name movieLengthHMS would be more clear.
2530
// f) Try experimenting with different values of movieLength. Will this code work for all values of movieLength? Explain your answer
31+
// No, it will not work for all values of movieLength.
32+
// if movieLength is above 24 hours, the code will create an incorrect format of hours.
33+
// example 52:26:24 which don't make sense.

Sprint-1/3-mandatory-interpret/3-to-pounds.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,17 @@
1-
const penceString = "399p";
1+
const penceString = "399p";// initialises a string variable with the value "399p"
22

33
const penceStringWithoutTrailingP = penceString.substring(
44
0,
55
penceString.length - 1
6-
);
6+
);// removes the last character "p" from the penceString and stores the result in a new variable called penceStringWithoutTrailingP. The substring method is used to extract a portion of the string, starting from index 0 and ending at the second-to-last index (length - 1).
77

88
const paddedPenceNumberString = penceStringWithoutTrailingP.padStart(3, "0");
9+
//padStart method is used to add leading zeros to the penceStringWithoutTrailingP until it reaches a length of 3 characters. The result is stored in a new variable called paddedPenceNumberString.
910
const pounds = paddedPenceNumberString.substring(
1011
0,
1112
paddedPenceNumberString.length - 2
1213
);
13-
14+
//
1415
const pence = paddedPenceNumberString
1516
.substring(paddedPenceNumberString.length - 2)
1617
.padEnd(2, "0");

0 commit comments

Comments
 (0)