Skip to content

Commit 85e1e3e

Browse files
authored
Answering questions by paceing // to separate from the code. and other modifiy the code taccording to the error
1 parent 0b19fc5 commit 85e1e3e

File tree

11 files changed

+90
-8
lines changed

11 files changed

+90
-8
lines changed

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@ 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+
78
// Answer
9+
810
// Line 3; when we the right side first count in the right side is considerd as 0 so 0+1 will be 1.
911
// But the = sign does not mean the mathimatical equal, its function is to take the result on the right and store it on the left.
1012
// Therfore if we write the same code in next line the result is not one but 2

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,9 @@ 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 = base.slice(lastDotIndex + 1);
23+
2224

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

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

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,22 @@ 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+
// Answer
12+
13+
// 1.
14+
// The num in this scenario represent any integer between 1 and 100
15+
16+
// 2.
17+
// Math.floor: rounds the number down to the nearest whole number which means it ignores the number to the right of the point. eg. 4.7=4
18+
// Math.random is a js code that returns any random number that is greater than or equal to 0 and less than 1
19+
//* is multiplication
20+
// maximum is the maximum given number, in this case 100
21+
//- is a subtraction
22+
// minimum is the minimum given number, in this case 1
23+
//(maximum - minimum +1) this is subtracting the minimum number from the maximum and add 1, in this case (100-1+1)=100
24+
//+ minimum: this turns the value by adding 1 to the whole equation.
25+
26+
//3.
27+
28+
console.log(num)

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
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?

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+
console.log(age)

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
// Currently trying to print the string "I was born in Bolton" but it isn't working...
22
// what's the error ?
33

4-
console.log(`I was born in ${cityOfBirth}`);
4+
55
const cityOfBirth = "Bolton";
6+
console.log(`I was born in ${cityOfBirth}`);

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

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,13 @@ 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+
//Answer
12+
13+
// This code is not working because slice() is working with "string" or "arrays" but not with numbers. and cardNumber is a number.
14+
// So the error is "TypeError:cardNumber.slice is not a function"\
15+
// slice() didn't recognize the number as I expected before.
16+
17+
const cardNumber = 4533787178994213;
18+
const last4Digits = String(cardNumber).slice(-4);
19+
console.log(last4Digits)

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,5 @@
11
const 12HourClockTime = "20:53";
2-
const 24hourClockTime = "08:53";
2+
const 24hourClockTime = "08:53";
3+
// the 12 and 24 are changing position
4+
const 24HourClockTime = "20:53";
5+
const 12hourClockTime = "08:53";

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

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,37 @@ console.log(`The percentage change is ${percentageChange}`);
1313

1414
// a) How many function calls are there in this file? Write down all the lines where a function call is made
1515

16+
// There are five functions calls.
17+
//carPrice.replaceAll(",", "")
18+
//Number(carPrice.replaceAll(",", ""))
19+
//priceAfterOneYear.replaceAll("," "")
20+
//Number(priceAfterOneYear.replaceAll("," ""))
21+
//console.log(`The percentage change is ${percentageChange}`)
22+
1623
// 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?
1724

25+
// When I run the code the error is "syntaxError: missing ) after argument list.
26+
// The error comes from line 5
27+
// The error occurs due to the missing coma between the two strings in the replaceAll() call.
28+
// Add coma between the two strings "priceAfterOneYear = Number(priceAfterOneYear.replaceAll(",", ""));"
29+
1830
// c) Identify all the lines that are variable reassignment statements
1931

32+
// there are to lines that state variable reassignment
33+
// carPrice = Number(carPrice.replaceAll(",", ""));
34+
// priceAfterOneYear = Number(priceAfterOneYear.replaceAll("," ""));
35+
2036
// d) Identify all the lines that are variable declarations
2137

38+
// There are fore variable declarations (line 1, line 2, line 7, line 8)
39+
// let carPrice = "10,000";
40+
// let priceAfterOneYear = "8,543";
41+
// const priceDifference = carPrice - priceAfterOneYear;
42+
// const percentageChange = (priceDifference / carPrice) * 100;
43+
44+
2245
// e) Describe what the expression Number(carPrice.replaceAll(",","")) is doing - what is the purpose of this expression?
46+
47+
// carprice at line 1 is a string in order to calculate for the next line of codes you have to change the string ti number.
48+
// carPrice.replaceAll(",","")). delete the coma in between the number (e.g from "10,000" to "10000")
49+
// number() change the string to number ("10000" to 10000)

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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+
// There are 6 variable declaration. "line1, line3, line4, line6, line7, line9"
1516

1617
// b) How many function calls are there?
18+
// There is only one function call in this program "console.log(result);"
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+
// % is called remainder. There fore movieLength % 60 represents the remainder of the movie length after dividing by 60.
2023

2124
// d) Interpret line 4, what does the expression assigned to totalMinutes mean?
25+
// totalMinutes are calculated by subtracting the remaining seconds from movie length and divided by 60 to get full minutes. this helps to get a number which divided by 60 with out reminder.
2226

2327
// e) What do you think the variable result represents? Can you think of a better name for this variable?
28+
// result represents the total length of the movie in the form of Hour: minute: second
29+
// moveDurationFormatted can be a better name to replace result.
2430

2531
// f) Try experimenting with different values of movieLength. Will this code work for all values of movieLength? Explain your answer
32+
// Yes it works for all value. the only thing that is concerning is the validation of movieLength as the negative integer also gives value which is unrealistic.

0 commit comments

Comments
 (0)