Skip to content

Commit 9b108f2

Browse files
committed
done with Sprint !
1 parent 3802e7d commit 9b108f2

File tree

3 files changed

+30
-13
lines changed

3 files changed

+30
-13
lines changed

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

Lines changed: 6 additions & 1 deletion
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,16 @@ 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+
// Anwer: The function is called 4 times in the code line 7 and 8 then we have the built-in functions line 4 and 5
1516

1617
// 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?
18+
// Answer: The error is coming from line 5 a comma is missing between the quotes '(priceAfterOneYear.replaceAll("," ""))'
1719

1820
// c) Identify all the lines that are variable reassignment statements
21+
// Answer: Line 4 and 5
1922

2023
// d) Identify all the lines that are variable declarations
24+
// Answer: Line 1, 2, 7 and 8
2125

2226
// e) Describe what the expression Number(carPrice.replaceAll(",","")) is doing - what is the purpose of this expression?
27+
// Answer: It removing all the commas and also converting the values to a number

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

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

33
const remainingSeconds = movieLength % 60;
44
const totalMinutes = (movieLength - remainingSeconds) / 60;
@@ -12,14 +12,20 @@ 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+
// Answer: There are 6
1516

1617
// b) How many function calls are there?
18+
// Answer: There are no function calls
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
22+
// Answer: This devides values and gives us the remainder
2023

2124
// d) Interpret line 4, what does the expression assigned to totalMinutes mean?
25+
// Answer: It subtracts remaining seconds from movie length then devides that by 60
2226

2327
// e) What do you think the variable result represents? Can you think of a better name for this variable?
28+
// Answer: This will display the movie length formatted in hours, minutes and seconds, it can be named totalTime
2429

2530
// f) Try experimenting with different values of movieLength. Will this code work for all values of movieLength? Explain your answer
31+
// Answer: Yes it works with all values, this can be because there are template litterals in the result variable
Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,12 @@
11
const penceString = "399p";
22

3-
const penceStringWithoutTrailingP = penceString.substring(
4-
0,
5-
penceString.length - 1
6-
);
3+
const penceStringWithoutTrailingP = penceString.substring(0, penceString.length - 1);
74

85
const paddedPenceNumberString = penceStringWithoutTrailingP.padStart(3, "0");
9-
const pounds = paddedPenceNumberString.substring(
10-
0,
11-
paddedPenceNumberString.length - 2
12-
);
136

14-
const pence = paddedPenceNumberString
15-
.substring(paddedPenceNumberString.length - 2)
16-
.padEnd(2, "0");
7+
const pounds = paddedPenceNumberString.substring(0, paddedPenceNumberString.length - 2);
8+
9+
const pence = paddedPenceNumberString.substring(paddedPenceNumberString.length - 2).padEnd(2, "0");
1710

1811
console.log(${pounds}.${pence}`);
1912

@@ -25,3 +18,16 @@ console.log(`£${pounds}.${pence}`);
2518

2619
// To begin, we can start with
2720
// 1. const penceString = "399p": initialises a string variable with the value "399p"
21+
22+
// 2. penceStringWithoutTrailingP the last "p" from line 1 is removed
23+
// substring() method will select a charactor from index 0 to -1, and return the new string "-1 is the last charactor" then we get "399"
24+
25+
// 3. paddedPenceNumberString this is assingned to the variable penceStringWithoutTrailingP where a charactor is added to the beggining of the string by the method padStart
26+
// 3 will add 2 zeros to the begining of the string, we have padStart(3, "0") and we already have three charactor
27+
// if it was padStart(4, "0") then the result was "0399"
28+
29+
// 4. pounds will take the paddedPenceNumberString, select all the charactors exept the last two
30+
31+
// 5. pence selects the values in paddedPenceNumberString, then makes sure we have the last we have two digits at the end
32+
33+
// console will print the output value in pounds

0 commit comments

Comments
 (0)