Skip to content

Commit e83c8e2

Browse files
committed
add interpretations to exercises 1-3 in 3-mandatory-interpret
1 parent 2d32e8e commit e83c8e2

3 files changed

Lines changed: 52 additions & 0 deletions

File tree

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

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,22 @@ console.log(`The percentage change is ${percentageChange}`);
1313

1414
// a) How many function calls are there in this file? Write down all the lines where a function call is made
1515

16+
// 5 function calls in total:
17+
// on lines: 4 (2), 5 (2) and 10
18+
1619
// 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?
1720

21+
// line 5. it says it's a syntax error, and it identifies a missing closing parenthesis as the issue, but the reason it thought that is that it expected the function to close after the comma, since there was no comma outside of the quotation marks. to fix this, I just added a comma between the two arguments in the .replaceAll() function.
22+
1823
// c) Identify all the lines that are variable reassignment statements
1924

25+
//these would be the line 4 and 5
26+
2027
// d) Identify all the lines that are variable declarations
2128

29+
//these would be the ones starting with let or const:
30+
//lines 1,2,7,8
31+
2232
// e) Describe what the expression Number(carPrice.replaceAll(",","")) is doing - what is the purpose of this expression?
33+
34+
//in the carPrice variable we want to replace all instances of commas with nothing - so we want to remove the thousand separators. The result is then passed in to the Number() function to convert this string to a number.

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

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,24 @@ 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+
//6 (the lines starting with const)
1516

1617
// b) How many function calls are there?
18+
// line 10 - the log() function is called
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+
//the modulo operator is for checking remainders in a division. so in this case we want to check what is the remainder if we divide the movieLength by 60
2023

2124
// d) Interpret line 4, what does the expression assigned to totalMinutes mean?
25+
// movieLength is the length of the movie measured in seconds.
26+
// remainingSeconds is the seconds remaining after dividing the movieLength by 60 (so checking how many seconds remain after the rest fits into minutes)
27+
//line 4 calculates the total number of minutes in a movie by taking away the trailing seconds (that would remain if we converted to minutes) and dividing that by 60 (since there are 60 seconds in a minute)
2228

2329
// e) What do you think the variable result represents? Can you think of a better name for this variable?
30+
//it gives us the length of a movie in the format of: hh:mm:ss
31+
//maybe movieLengthInHMS or movieLengthFormatted
2432

2533
// f) Try experimenting with different values of movieLength. Will this code work for all values of movieLength? Explain your answer
34+
//I think so. Unless a movie might be a year long, but to be fair, even then it works, only then we might need to introduce a day into the result.
35+
//other issues might be if the variable movieLength is not valid such as negative number, or not a number, then there might be issues. This could be solved with validation

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

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,3 +25,33 @@ console.log(`£${pounds}.${pence}`);
2525

2626
// To begin, we can start with
2727
// 1. const penceString = "399p": initialises a string variable with the value "399p"
28+
/*2. (lines 3-6) const penceStringWithoutTrailingP = penceString.substring(
29+
0,
30+
penceString.length - 1
31+
);
32+
initialise a variable that takes part of penceString (.substring)
33+
the substring being: starting from position 0 (so the first character) until position: length of penceString minus 1 (so the last character, which is the letter p)
34+
*/
35+
/* 3. (line 8): const paddedPenceNumberString = penceStringWithoutTrailingP.padStart(3, "0");
36+
this initialises another variable, paddedPenceNumberString that takes the value of penceStringWithoutTrailingP , pads it with 0's on the left hand side to make up three digits in total, so for example if the number is 2 digit, then the 1st digit will be 0
37+
*/
38+
39+
/* 4 (lines 9-12)
40+
const pounds = paddedPenceNumberString.substring(
41+
0,
42+
paddedPenceNumberString.length - 2
43+
);
44+
initialises another variable, pounds that is made up of the first few digits of paddedPenceNumberString, where few would be length of paddedPenceNumberString-2 (so essentially leaving the last 2 characters out)
45+
*/
46+
47+
/* 5. (lines 14-16)
48+
const pence = paddedPenceNumberString
49+
.substring(paddedPenceNumberString.length - 2)
50+
.padEnd(2, "0");
51+
initialises another variable, pence that takes the last two characters of paddedPenceNumberString, and makes sure its 2 digits by paddign it with 0's to 2 places
52+
*/
53+
54+
/* 6 (line18)
55+
console.log(`£${pounds}.${pence}`);
56+
logs the values of pounds and pennies as a string to the console using a pound sign to start with
57+
*/

0 commit comments

Comments
 (0)