You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
// The last4Digits variable should store the last 4 digits of cardNumber
5
7
// However, the code isn't working
6
8
// Before running the code, make and explain a prediction about why the code won't work
9
+
10
+
// I think the code will not work because cardNumber is a number, and .slice() only works with strings.
11
+
7
12
// Then run the code and see what error it gives.
13
+
14
+
//TypeError: cardNumber.slice is not a function
15
+
16
+
8
17
// Consider: Why does it give this error? Is this what I predicted? If not, what's different?
18
+
19
+
// The error happens because slice() cannot be used on a number. It only works on strings. Yes, this is what I predicted because I expected an error caused by trying to use slice() on a number. There is no difference between my prediction and the actual error.
20
+
21
+
9
22
// Then try updating the expression last4Digits is assigned to, in order to get the correct value
@@ -12,11 +12,19 @@ console.log(`The percentage change is ${percentageChange}`);
12
12
// Read the code and then answer the questions below
13
13
14
14
// a) How many function calls are there in this file? Write down all the lines where a function call is made
15
+
//The function call are made five times
16
+
//line 4, 5, 10
15
17
16
18
// 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?
19
+
// Line 5, A comma was missing between the arguments. Include a comma between the arguments to fix the error.
17
20
18
21
// c) Identify all the lines that are variable reassignment statements
19
22
23
+
//Lines 7 & 8
24
+
20
25
// d) Identify all the lines that are variable declarations
21
26
27
+
//Lines 1 & 2
28
+
22
29
// e) Describe what the expression Number(carPrice.replaceAll(",","")) is doing - what is the purpose of this expression?
30
+
//It first removes all commas from the string (e.g. "10,000" becomes "10000"), then converts the resulting string into a number using Number(). This allows the value to be used in mathematical calculations.
0 commit comments