Skip to content

Commit 0db337a

Browse files
committed
work on errors,identifying codes and brief explanation of codes
1 parent 540b62a commit 0db337a

File tree

8 files changed

+65
-9
lines changed

8 files changed

+65
-9
lines changed

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+
/*when we try to write comment and instruction and we want the computer not to run it we can comment them using // for single line and /* for multiple lines. */

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
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+
// To reassign a value of age we have to use let not const.

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
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+
//the code try to log the variable before declaring the variable
7+
// if we declare and initialize the variable first then we can use it.

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
const cardNumber = 4533787178994213;
1+
const cardNumber = "4533787178994213";
22
const last4Digits = cardNumber.slice(-4);
33

44
// The last4Digits variable should store the last 4 digits of cardNumber
@@ -7,3 +7,6 @@ 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+
/* the code is not working because of the variable type which is .slice method work on
11+
string and array variable types not on number variable types to fix it we can change the variable type to
12+
string variable type by adding double quotation marks to the variable.*/

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,4 @@
1-
const 12HourClockTime = "20:53";
2-
const 24hourClockTime = "08:53";
1+
const hourClockTime12 = "20:53";
2+
const hourClockTime24 = "08:53";
3+
4+
// Numbers are not allowed as the first character in naming of variables.

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

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,26 @@ 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+
/* there are 5 function calls in this code.
16+
1) Number(carPrice.replaceAll(",","")); line 4.
17+
2) Number(priceAfterOneYear.replace("," "")) line 5.
18+
3) carPrice.replaceAll(",", "") line 4.
19+
4) priceAfterOneYear.replaceAll("," "") line 5.
20+
5) console.log(`The percentage change is ${percentageChange}`); line 10. */
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 coming from line 5 and the error is missing between the arguments.
1724

1825
// c) Identify all the lines that are variable reassignment statements
26+
/*on line 4- carPrice = Number(carPrice.replaceAll(",", ""));
27+
on line 5- priceAfterOneYear = Number(priceAfterOneYear.replaceAll(","), "")*/
1928

2029
// d) Identify all the lines that are variable declarations
30+
/* line 1- let carPrice = "10,000";
31+
line 2- let priceAfterOneYear = "8,543";
32+
line 7- const priceDifference = carPrice - priceAfterOneYear;
33+
line 8- const percentageChange = (priceDifference / carPrice) * 100;*/
2134

2235
// e) Describe what the expression Number(carPrice.replaceAll(",","")) is doing - what is the purpose of this expression?
36+
/* the expression doing changing the value of "10,000" to "10000" because comma count as part of a character after that
37+
changing the string variable type to number variable type. */

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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,23 @@ 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 declaration.
1516

1617
// b) How many function calls are there?
18+
// there is only one function call.
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+
/* the expression movieLength % 60 represents the returns of the remainder after dividing one number by another
23+
in this case 8784 % 60 and it return the remainder 24. */
2024

2125
// d) Interpret line 4, what does the expression assigned to totalMinutes mean?
26+
//This expression calculates the total full minutes in the movie by removing leftover seconds and converting seconds to minutes.
2227

2328
// e) What do you think the variable result represents? Can you think of a better name for this variable?
29+
//result represent the total movie length using hours,minutes and seconds,the better name can be totalMovieLength.
2430

2531
// f) Try experimenting with different values of movieLength. Will this code work for all values of movieLength? Explain your answer
32+
/*the code works for different values of movieLength it present the input movieLength by calculating the remainder and subtracting
33+
it with the initial input and using the method for the finding of the value for the rest of the variables and assign the values withe
34+
the variables of hours,minutes and seconds */

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

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,4 +24,26 @@ console.log(`£${pounds}.${pence}`);
2424
// Try and describe the purpose / rationale behind each step
2525

2626
// To begin, we can start with
27-
// 1. const penceString = "399p": initialises a string variable with the value "399p"
27+
// 1. const penceString = "399p": initializes a string variable with the value "399p"
28+
29+
/* 2. const penceStringWithoutTrailingP = penceString.substring(
30+
0,
31+
penceString.length - 1
32+
); : this part of the code have two steps,
33+
- inside assigning of variable there is a function call that replace the string "399p" by "399"
34+
- then assigning the variable penceStringWithoutTrailingP with new string "399" */
35+
36+
/* 3. const paddedPenceNumberString = penceStringWithoutTrailingP.padStart(3, "0"); this initializes new string value that have
37+
3 character if it's less than 3 it will add "0" in front of the string.*/
38+
39+
/* 4. const pounds = paddedPenceNumberString.substring(
40+
0,
41+
paddedPenceNumberString.length - 2
42+
); : this part of the code assigning const pound with value of string that length is
43+
reduced by -2 . */
44+
45+
/* 5. const pence = paddedPenceNumberString
46+
.substring(paddedPenceNumberString.length - 2)
47+
.padEnd(2, "0"); : let's break it down this code parts it have two steps first one is .substring(paddedPenceNumberString.length - 2)
48+
Takes the last 2 characters of the string and the second is .padEnd(2, "0") Ensures the result
49+
is at least length 2 if the length less than 2 it will add 0 at the end of the string. */

0 commit comments

Comments
 (0)