Skip to content

Commit a6db6fb

Browse files
committed
Done Sprint 1
1 parent b52ce70 commit a6db6fb

File tree

13 files changed

+105
-9
lines changed

13 files changed

+105
-9
lines changed

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,5 @@ let count = 0;
22

33
count = count + 1;
44

5-
// Line 1 makes a variable called count and gives the value 0. Line 3 ads 1 to the value of count. So after line 3, count has the value 1. If we were to run line 3 again, count would have the value 2. If we were to run line 3 again, count would have the value 3. And so on. Each time we run line 3, we add 1 to the value of count.
5+
// line 1 makes box called count and puts 0 inside it.
6+
// line 3 adds 1 to count.

Sprint-1/1-key-exercises/3-paths.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ console.log(`The base part of ${filePath} is ${base}`);
1717
// Create a variable to store the dir part of the filePath variable
1818
// Create a variable to store the ext part of the variable
1919

20-
const dir = ;
21-
const ext = ;
20+
const dir = filePath.slice(0, lastSlashIndex)
21+
const lastDotIndex = base.lastIndexOf(".");
22+
const ext = filePath.slice(lastDotIndex + 1);
2223

24+
// https://www.google.com/search?q=slice+mdn

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,6 @@ const num = Math.floor(Math.random() * (maximum - minimum + 1)) + minimum;
77
// Try breaking down the expression and using documentation to explain what it means
88
// It will help to think about the order in which expressions are evaluated
99
// Try logging the value of num and running the program several times to build an idea of what the program is doing
10+
11+
//num is random whole number between 1 and 100.
12+
//each time the program runs, it creates a different number in that range.

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,6 @@
11
This is just an instruction for the first activity - but it is just for human consumption
2-
We don't want the computer to run these 2 lines - how can we solve this problem?
2+
We don't want the computer to run these 2 lines - how can we solve this problem?
3+
4+
5+
// We can add // at the start of the lines to turn them into comments.
6+
// The computer ignores comments, so it will not run them.

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,8 @@
22

33
const age = 33;
44
age = age + 1;
5+
6+
// The error happens because age was declared using const.
7+
// const variable canot be changed.
8+
// We trying to change age ,so casue error.
9+
// It should use let instead.

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,8 @@
33

44
console.log(`I was born in ${cityOfBirth}`);
55
const cityOfBirth = "Bolton";
6+
7+
// The error happens because cityOfBirth is used before it is declared.
8+
// Const variable cannot be used before declaration.
9+
// Move the variable delaration before the console.log line.
10+

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,9 @@ const last4Digits = cardNumber.slice(-4);
77
// Then run the code and see what error it gives.
88
// Consider: Why does it give this error? Is this what I predicted? If not, what's different?
99
// Then try updating the expression last4Digits is assigned to, in order to get the correct value
10+
11+
12+
// The code will not work because slice() cannot be used on numbers.
13+
// Slice() only works on strings or arrays.
14+
//We need to convert the number to string first
15+
const last4Digits = cardNumber.to String().slice(-4);

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

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,8 @@
11
const 12HourClockTime = "20:53";
2-
const 24hourClockTime = "08:53";
2+
const 24hourClockTime = "08:53";
3+
4+
// Variables names cannot start with a number.
5+
// Rename the variables so they start with a letter.
6+
const hour12ClockTime = "20:35";
7+
const hour24ClockTime = "08:35";
8+

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

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,19 +4,40 @@ let priceAfterOneYear = "8,543";
44
carPrice = Number(carPrice.replaceAll(",", ""));
55
priceAfterOneYear = Number(priceAfterOneYear.replaceAll("," ""));
66

7-
const priceDifference = carPrice - priceAfterOneYear;
8-
const percentageChange = (priceDifference / carPrice) * 100;
7+
const PriceDifference = carPrice - priceAfterOneYear;
8+
const PercentageChange = (PriceDifference / carPrice) * 100;
99

10-
console.log(`The percentage change is ${percentageChange}`);
10+
console.log(`The percentage change is ${PercentageChange}`);
1111

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+
// there are 4 function calls in this file.
16+
carPrice.replaceAll(",", "")
17+
priceAfterOneYear.replaceAll(",", "")
18+
Number(carPrice.replaceAll(",", ""))
19+
Number(priceAfterOneYear.replaceAll(",", ""))
20+
1521

1622
// 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?
23+
// the error is comin from this line
24+
25+
priceAfterOneYear = Number(priceAfterOneYear.replaceAll("," ""));
26+
// the error happens becuae there is missing comma inside reaplaceAll().
27+
//The correct line should be
28+
priceAfterOneYear = Number(priceAfterOneYear.replaceAll(",", ""));
1729

1830
// c) Identify all the lines that are variable reassignment statements
31+
// This lines
32+
carPrice = Number(carPrice.reaplaceAll(",", ""));
1933

2034
// d) Identify all the lines that are variable declarations
35+
let carPrice = 10,000";
36+
let priceAfterOneYear = "8,543";
37+
const priceDifference = carPrice - priceAfterOneyear;
38+
const percentageChange = (priceDifference / carPrice) * 100;
39+
2140

2241
// e) Describe what the expression Number(carPrice.replaceAll(",","")) is doing - what is the purpose of this expression?
42+
Number(carPrice.replaceAll(",", ""))
43+
// It removes commas from the number string and converts the results into a real number so calculation can be done.

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

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,35 @@ 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+
There are 6 variable declarations in this program.
16+
movieLength
17+
remainingSeconds
18+
totalMinutes
19+
remainingMinutes
20+
totalHours
21+
result
1522

1623
// b) How many function calls are there?
24+
There is 1 function call in this program.
25+
console.log(result)
26+
// The function call is on line 10, where we are calling the console.log function to print the value of result to the console.
1727

1828
// c) Using documentation, explain what the expression movieLength % 60 represents
1929
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Arithmetic_Operators
2030

31+
// % is the remainder after dividing movielenth by 60. It gives us the number of seconds that are left over after we have taken out all the whole minutes from the movie length
32+
33+
34+
2135
// d) Interpret line 4, what does the expression assigned to totalMinutes mean?
36+
// first remove the extra seconds.
37+
// then divide by 60 to get the total number of minutes in the movie length.
2238

2339
// e) What do you think the variable result represents? Can you think of a better name for this variable?
40+
// The variable result represents the formatted time in hours:minutes:seconds format.
41+
// A better name for this varibale could be formattedTime.
2442

2543
// f) Try experimenting with different values of movieLength. Will this code work for all values of movieLength? Explain your answer
44+
// no, this code will not work good for all values of movielength.
45+
// it will only right for postitive whole number of seconds.
46+
// if movieLength is nagatuve or not a whole number, the result will not be right.

0 commit comments

Comments
 (0)