Skip to content

Commit 9dcebe9

Browse files
committed
Erros Identified for all file of Sprint-1
1 parent 5e52076 commit 9dcebe9

9 files changed

Lines changed: 91 additions & 14 deletions

File tree

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ console.log(`The base part of ${filePath} is ${base}`);
1919

2020
const lastindex1 = filePath.lastIndexOf("/");
2121
const dir1 = filePath.slice(0,lastindex1);
22-
console.log(`The variable contains directory path of a file: ${dir1}`);
22+
console.log(`The variable contains directory path of a file: ${dir1}`);
2323
const dir = filePath.slice(0,44);
2424
console.log(`This variable stores directory path of a file: ${dir}`);
2525
//I did from both ways just to clear my concepts.

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,4 @@
1-
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?
1+
//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?
3+
4+
//As age was constant there we can't change the value of age like this. I made age let so it can change the value of age.

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

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
11
// trying to create an age variable and then reassign the value by 1
22

3-
const age = 33;
3+
let age = 33;
44
age = age + 1;
5+
console.log(age);
6+
7+
/*As age was constant here we can't change the value of age like this.
8+
because in line 4, the value of age is incremented by 1 and assigning again to age but if variable is const we can't change.
9+
I made age let so I can change the value of age.*/

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

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,13 @@
11
// Currently trying to print the string "I was born in Bolton" but it isn't working...
22
// what's the error ?
3-
4-
console.log(`I was born in ${cityOfBirth}`);
53
const cityOfBirth = "Bolton";
4+
console.log(`I was born in ${cityOfBirth}`);
5+
6+
/*
7+
It a reference error, we cannot access cityOfBirth before initializing it. We are trying to fetch a
8+
value of cityOfbirth without declaring it. The interpreter first runs the line 1 i.e console.log one
9+
and try to find a value but its not declare and it will give a error. Though we have declare is in line 2
10+
but js is an interpreted language that interpret line by line and runs the code.
11+
The cityOfBirth is in locked state right now js couldn't access until reaches to it.
12+
Right now it is in temporal locked state.
13+
*/

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

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,24 @@
1-
const cardNumber = 4533787178994213;
1+
const cardNumber = "4533787178994213";
22
const last4Digits = cardNumber.slice(-4);
3+
console.log(last4Digits);
4+
5+
//const cardNumber = 4533787178994213;
6+
//const lastdig = cardNumber.toString().slice(-4);
7+
//console.log(lastdig);
38

49
// The last4Digits variable should store the last 4 digits of cardNumber
510
// However, the code isn't working
611
// Before running the code, make and explain a prediction about why the code won't work
712
// Then run the code and see what error it gives.
813
// Consider: Why does it give this error? Is this what I predicted? If not, what's different?
914
// Then try updating the expression last4Digits is assigned to, in order to get the correct value
15+
16+
/*
17+
Slice is a string method we are using it on number.
18+
We can convert the number into string and then apply slice() method to retrieve last four digits or simply we
19+
can declare number as a string using quotes.
20+
Run a code : It gives TypeError and js gives this error when method/operation isn't valid for particular data
21+
type using.
22+
I got the idea of data type that slice() method can't use for this data type.
23+
I attempt it by both ways I mentioned above.
24+
*/

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

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,6 @@
1-
const 12HourClockTime = "8:53pm";
2-
const 24hourClockTime = "20:53";
1+
const HourClockTime12 = "8:53pm";
2+
const hourClockTime24 = "20:53";
3+
4+
/*The variable name cannot start with number. It can begin with _, $ or a letter.
5+
I fixed it by renaming the variable names.
6+
*/

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

Lines changed: 14 additions & 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;
@@ -12,11 +12,24 @@ console.log(`The percentage change is ${percentageChange}`);
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+
/*
16+
replaceAl() : In line 4, replaceAll(",", "") and in line 5, replaceAll("," "")
17+
Number() : In line 4, Number(carPrice.replaceAll(",", "")) and in line 5, Number(priceAfterOneYear.replaceAll("," "")
18+
console.log: In line 10, console.log(`The percentage change is ${percentageChange}`);
19+
*/
1520

1621
// 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?
22+
//Basically, the error is coming from line 5. It missed the , between two values.
23+
//priceAfterOneYear = Number(priceAfterOneYear.replaceAll("," , ""));
1724

1825
// c) Identify all the lines that are variable reassignment statements
26+
//line 4 and line 5
1927

2028
// d) Identify all the lines that are variable declarations
29+
//line 1, line 2, line 7 and line 8
2130

2231
// e) Describe what the expression Number(carPrice.replaceAll(",","")) is doing - what is the purpose of this expression?
32+
/* Number(carPrice.replaceAll(",","")) let's breakdown this to understand.
33+
carPrice.replaceAll(",","") -> replaces , and it becomes 1000
34+
Number("1000") converts string to a number -> 1000.
35+
*/

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

Lines changed: 11 additions & 4 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 = 8784; // length of movie in seconds
2+
const movieLength = 9893;
33
const remainingSeconds = movieLength % 60;
44
const totalMinutes = (movieLength - remainingSeconds) / 60;
55

@@ -12,14 +12,21 @@ 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+
//six
1516

1617
// b) How many function calls are there?
18+
// 1 i.e console.log
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+
// This is a reminder operator. It divides one number by another and gives a reminder.
2023

2124
// d) Interpret line 4, what does the expression assigned to totalMinutes mean?
22-
25+
/* const totalMinutes = (movieLength - remainingSeconds) / 60
26+
Firstly it will evaluate bracket i.e (movieLength - remainingSeconds) and then divide the value by 60.
27+
*/
2328
// e) What do you think the variable result represents? Can you think of a better name for this variable?
24-
29+
// The result represents the how long the movie is, in hours, minutes and seconds. It can named as MovieDuration.
2530
// f) Try experimenting with different values of movieLength. Will this code work for all values of movieLength? Explain your answer
31+
// Yes, I changed the value of movieLength and it worked. The movieLength is the variable used in calculating other
32+
// values and to evaluate the total length of movie.

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

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,3 +25,26 @@ 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+
/*line 3-6.
29+
const penceStringWithoutTrailingP = penceString.substring(
30+
0,
31+
penceString.length - 1
32+
) : calculate the length and then subtract 1,length is 4-1=3 , and extract substring 0 to 3 i.e 399
33+
/*
34+
line 8.Padstart puts zero in beginning until it meets the desire length. The length is 3 and string length is already 3, so it remained unchanged.
35+
paddedPenceNumberString = "399"
36+
line 9-12.
37+
const pounds = paddedPenceNumberString.substring(
38+
0,
39+
paddedPenceNumberString.length - 2
40+
); paddedPenceNumberString.length - 2: 3-2=1 -> paddedPenceNumberString.substring(0,1)-> pounds="3"
41+
line 14-16.
42+
const pence = paddedPenceNumberString
43+
.substring(paddedPenceNumberString.length - 2)
44+
.padEnd(2, "0");
45+
(paddedPenceNumberString.length - 2)-> 3-2 = 1 -> substring(1).padEnd(2,"0")-> 99, the length is already two.
46+
pence ="99"
47+
48+
console.log(`£${pounds}.${pence}`);
49+
£3.99
50+
*/

0 commit comments

Comments
 (0)