Skip to content

Commit faf70eb

Browse files
committed
comments in percentage change, time format, and to pounds calculations
1 parent 10e3a62 commit faf70eb

File tree

3 files changed

+42
-2
lines changed

3 files changed

+42
-2
lines changed

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

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,3 +20,23 @@ console.log(`The percentage change is ${percentageChange}`);
2020
// d) Identify all the lines that are variable declarations
2121

2222
// e) Describe what the expression Number(carPrice.replaceAll(",","")) is doing - what is the purpose of this expression?
23+
24+
priceAfterOneYear = Number(priceAfterOneYear.replaceAll("," ""));
25+
26+
// a) there are 5 function calls in this file,// Line 4: replaceAll(",", "") and Number()
27+
// Line 5: replaceAll(",", "") and Number()
28+
// Line 9: console.log()
29+
30+
// b) The error is coming from line 4 and line 5.
31+
// The error occurs because the replaceAll method is being called on a string that contains a comma, which is not a valid number.
32+
// To fix this problem, we can remove the commas from the strings before converting them to numbers.
33+
34+
// c) The variable reassignment statements are on line 4 and line 5, where carPrice and
35+
// priceAfterOneYear are being reassigned to the result of the Number() function.
36+
37+
// d) The variable declarations are on line 1 and line 2, where carPrice and priceAfterOneYear are declared and initialized with string values.
38+
39+
// e) The expression Number(carPrice.replaceAll(",","")) is doing the following:
40+
// 1. This part of the expression takes the string value of carPrice (which is "10,000") and removes all comma, resulting in the string "10000".
41+
// 2. Number(...): This part takes the resulting string "10000" and converts it into a number (10000).
42+

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,3 +23,10 @@ console.log(result);
2323
// e) What do you think the variable result represents? Can you think of a better name for this variable?
2424

2525
// f) Try experimenting with different values of movieLength. Will this code work for all values of movieLength? Explain your answer
26+
27+
// a) There are 6 variable declarations in this program: movieLength, remainingSeconds, totalMinutes, remainingMinutes, totalHours, and result.
28+
// b) There is 1 function call in this program: console.log(result).
29+
// c) The movieLength % 60 calculates the remainder. This gives us the number of seconds .
30+
// d) The totalMinutes subtracts the extra seconds to get a clean number, then divides by 60 to find the total whole minutes.
31+
// e) The variable result represents the formatted string of hours, minutes, and seconds for the movie length. A better name could be formattedTime.
32+
// f) This code will work for positive integers, but it doesn't add a leading zero to single digits (e.g., it prints 2:5:9 instead of 02:05:09).

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

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,5 +23,18 @@ console.log(`£${pounds}.${pence}`);
2323
// You need to do a step-by-step breakdown of each line in this program
2424
// Try and describe the purpose / rationale behind each step
2525

26-
// To begin, we can start with
27-
// 1. const penceString = "399p": initialises a string variable with the value "399p"
26+
27+
//1. const penceString = "399p": initializes a string variable with the value "399p"
28+
29+
// 2 to 6.const penceStringWithoutTrailingP = penceString.substring(0,penceString.length - 1);
30+
// removes the (p) at the end determined by removing the sudstring at the total length of the string -1
31+
32+
// 8.const paddedPenceNumberString = penceStringWithoutTrailingP.padStart(3, "0");
33+
// makes sure the string is at least 3 characters long and if it is not it padds it with "0"
34+
35+
// 9.const pounds = paddedPenceNumberString.substring( 0, paddedPenceNumberString.length - 2);
36+
// gets the ammout of pounds by making a sub string that starts at the firts character (0) to the paddedPenceNumberString length -2 to exclued the last 2 characters (the p)
37+
38+
// 10.
39+
// 18.console.log(`£${pounds}.${pence}`);
40+
// gives the console the result using a string literal

0 commit comments

Comments
 (0)