Skip to content

Commit a4c8522

Browse files
committed
3-mandatory-interpret done
1 parent f3b8cf5 commit a4c8522

File tree

6 files changed

+44
-10
lines changed

6 files changed

+44
-10
lines changed

Sprint-1/1-key-exercises/1-count.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,4 @@ count = count + 1;
44

55
// Line 1 is a variable declaration, creating the count variable with an initial value of 0
66
// Describe what line 3 is doing, in particular focus on what = is doing
7+
//Answer : Line 3 increases the value of count by 1 and then reassigns it to count with new value.

Sprint-1/1-key-exercises/4-random.js

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,18 @@ const maximum = 100;
33

44
const num = Math.floor(Math.random() * (maximum - minimum + 1)) + minimum;
55

6+
console.log(num);
7+
68
// In this exercise, you will need to work out what num represents?
9+
10+
//Answer : num represents a random integer between 1 and 100
11+
12+
713
// Try breaking down the expression and using documentation to explain what it means
8-
// It will help to think about the order in which expressions are evaluated
9-
// Try logging the value of num and running the program several times to build an idea of what the program is doing
14+
15+
//1- Math.floor(...) rounds the number down to the nearest whole number, giving an integer from 0 to 99.
16+
//2- Math.random() generates a decimal number between 0 and 1.
17+
//3- Math.random() * (maximum - minimum + 1) make sure that decimal to a range from 0 up to (maximum - minimum + 1).
18+
1019

1120

12-
//Answer : num represents a random integer between 1 and 100

Sprint-1/2-mandatory-errors/4.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
const 12HourClockTime = "20:53";
2-
const 24hourClockTime = "08:53";
1+
// const 12HourClockTime = "20:53";
2+
// const 24hourClockTime = "08:53";
33

44

5-
//identifiers cannot start with a number in Javascript
5+
//identifiers cannot start with a number in Javascript.

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

Lines changed: 8 additions & 3 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;
@@ -11,12 +11,17 @@ console.log(`The percentage change is ${percentageChange}`);
1111

1212
// Read the code and then answer the questions below
1313

14-
// a) How many function calls are there in this file? Write down all the lines where a function call is made
14+
// a) How many function calls are there in this file? Write down all the lines where a function call is made :
15+
//Answer : 5 functions
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+
//Answe: line 5 . we need a comma (,) between the arguments.puting (,) between ("," "")
1719

18-
// c) Identify all the lines that are variable reassignment statements
20+
// c) Identify all the lines that are variable reassignment statements :
21+
//Answe: line 4 and line 5
1922

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

2226
// e) Describe what the expression Number(carPrice.replaceAll(",","")) is doing - what is the purpose of this expression?
27+
//Answer: Remove formatting commas from the price string and then convert it to a number so we can do arithmetic.

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

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,27 @@ console.log(result);
1111

1212
// For the piece of code above, read the code and then answer the following questions
1313

14-
// a) How many variable declarations are there in this program?
14+
// a) How many variable declarations are there in this program?
15+
//Answer: 6
16+
1517

1618
// b) How many function calls are there?
19+
//Answer: 1
20+
1721

1822
// c) Using documentation, explain what the expression movieLength % 60 represents
1923
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Arithmetic_Operators
24+
//Answer: % is the modulus operator and movieLength % 60 gives the remainder when movieLength is divided by 60.
25+
2026

2127
// d) Interpret line 4, what does the expression assigned to totalMinutes mean?
28+
//Answer: movieLength - remainingSeconds → subtracts the leftover seconds, leaving only the total number of seconds that make full minutes
29+
//Dividing by 60 converts those seconds to total whole minutes So totalMinutes is the total minutes in the movie ignoring leftover seconds
30+
2231

2332
// e) What do you think the variable result represents? Can you think of a better name for this variable?
33+
//Answer: result is a string representing the movie length in HH:MM:SS format and better name MovieTimeFormat
34+
2435

2536
// f) Try experimenting with different values of movieLength. Will this code work for all values of movieLength? Explain your answer
37+
//Answer: It just works for positive integer

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,29 @@
11
const penceString = "399p";
2+
//Initialize a string variable representing the price in pence with a trailing "p" characte
23

34
const penceStringWithoutTrailingP = penceString.substring(
45
0,
56
penceString.length - 1
67
);
8+
//Remove the "p" so we can manipulate the numeric value
79

810
const paddedPenceNumberString = penceStringWithoutTrailingP.padStart(3, "0");
11+
// Pad the string to at least 3 digits so Makes it easier to separate pounds and pence consistently.
12+
913
const pounds = paddedPenceNumberString.substring(
1014
0,
1115
paddedPenceNumberString.length - 2
1216
);
17+
//Extract the pounds part so This gives the whole pounds part of the price.
1318

1419
const pence = paddedPenceNumberString
1520
.substring(paddedPenceNumberString.length - 2)
1621
.padEnd(2, "0");
1722

23+
//Extract the pence part so Ensures pence is always 2 digits.
24+
1825
console.log(${pounds}.${pence}`);
26+
//Combine pounds and pence into a formatted string
1927

2028
// This program takes a string representing a price in pence
2129
// The program then builds up a string representing the price in pounds

0 commit comments

Comments
 (0)