Skip to content

Commit d873260

Browse files
authored
Answering each question with in the file by puting // to separate from the code
1 parent a825bf7 commit d873260

File tree

5 files changed

+59
-2
lines changed

5 files changed

+59
-2
lines changed

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.

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

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
const penceString = "399p";
1+
onst penceString = "399p";
22

33
const penceStringWithoutTrailingP = penceString.substring(
44
0,
@@ -25,3 +25,13 @@ 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+
// 2. const penceStringWithoutTrailingP = penceString.substring( 0, penceString.length - 1);
29+
// This remove the p and left the string with only 399
30+
// 3. const paddedPenceNumberString = penceStringWithoutTrailingP.padStart(3, "0");
31+
// this code make sure that the string has 3 character. since one pound is equal 100 pence.
32+
// 4. const pounds = paddedPenceNumberString.substring( 0, paddedPenceNumberString.length - 2);
33+
// This code takes the number leaving the last 2 digits "in this case it takes 3 and leave 99"
34+
// 5. const pence = paddedPenceNumberString.substring(paddedPenceNumberString.length - 2) .padEnd(2, "0");
35+
// This code takes the last digit from the string and also make sure that it has only two digits this gives a "99" value.
36+
// 6. console.log(`£${pounds}.${pence}`);
37+
// his gives a result with £ sign and separated by . " in this case it gives £3.99 "

0 commit comments

Comments
 (0)