Skip to content

Commit 026209e

Browse files
committed
Completed 3-mandatory-interpret
1 parent 2e083e6 commit 026209e

File tree

3 files changed

+18
-11
lines changed

3 files changed

+18
-11
lines changed

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

Lines changed: 1 addition & 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;
Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
const movieLength = 8784; // length of movie in seconds
2-
1+
const movieLength = 44.69; // length of movie in seconds
2+
console.log("movieLength",movieLength)
33
const remainingSeconds = movieLength % 60;
44
const totalMinutes = (movieLength - remainingSeconds) / 60;
55

@@ -12,14 +12,15 @@ 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-
15+
// 6
1616
// b) How many function calls are there?
17-
17+
// 1
1818
// c) Using documentation, explain what the expression movieLength % 60 represents
1919
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Arithmetic_Operators
20-
20+
// It represents the amount of seconds left over after converting it into whole minutes.
2121
// d) Interpret line 4, what does the expression assigned to totalMinutes mean?
22-
22+
// It represents the total number of complete minutes in movieLength.
2323
// e) What do you think the variable result represents? Can you think of a better name for this variable?
24-
24+
// It represents the total running time of the movie in hours, minutes, and seconds. A better name for this variable could be movieDuration.
2525
// f) Try experimenting with different values of movieLength. Will this code work for all values of movieLength? Explain your answer
26+
// It works for most values except negative values and decimal values. This is because it only expects positive whole number inputs.

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

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,18 @@ const penceStringWithoutTrailingP = penceString.substring(
44
0,
55
penceString.length - 1
66
);
7-
7+
console.log("penceStringWithoutTrailingP",penceStringWithoutTrailingP)
88
const paddedPenceNumberString = penceStringWithoutTrailingP.padStart(3, "0");
9+
console.log("paddedPenceNumberString",paddedPenceNumberString)
910
const pounds = paddedPenceNumberString.substring(
1011
0,
1112
paddedPenceNumberString.length - 2
1213
);
13-
14+
console.log("pounds",pounds)
1415
const pence = paddedPenceNumberString
1516
.substring(paddedPenceNumberString.length - 2)
1617
.padEnd(2, "0");
17-
18+
console.log("pence",pence)
1819
console.log(${pounds}.${pence}`);
1920

2021
// This program takes a string representing a price in pence
@@ -25,3 +26,8 @@ console.log(`£${pounds}.${pence}`);
2526

2627
// To begin, we can start with
2728
// 1. const penceString = "399p": initialises a string variable with the value "399p"
29+
// 3-6. It makes a new string penceStringWithoutTrailingP containing all the characters of penceString except the last one which is the trailing character "P". It uses the substring() method by specifying the start and end indexes.
30+
// 8. It makes a new variable called paddedPenceNumberString, and then stores the result of calling padStart on the previous variable which is penceStringWithoutTrailingP. This adds zeros at the beginning of the string if its less than three characters.
31+
// 10. It makes a new variable called pounds, it takes paddedPenceNumberString and removes the last two characters. So the value of pounds is three.
32+
// 15. It makes a new variable called pence. It takes paddedPenceNumberString and takes the last two characters, if its less than two characters it will pad it with zeros until its two characters. So the result is 99.
33+
// 19. It console logs pounds and pence together as one string with a pound sign.

0 commit comments

Comments
 (0)