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
// Try breaking down the expression and using documentation to explain what it means
8
8
// It will help to think about the order in which expressions are evaluated
9
9
// Try logging the value of num and running the program several times to build an idea of what the program is doing
10
+
// num is a random whole number between 1 and 100. Math.random() gives a decimal between 0 and 1, multiplying it stretches that range to 0-100, Math.floor rounds it down to a whole number, and + minimum shifts it so the lowest possible value is 1 instead of 0.
// Currently trying to print the string "I was born in Bolton" but it isn't working...
2
2
// what's the error ?
3
3
4
-
console.log(`I was born in ${cityOfBirth}`);
5
4
constcityOfBirth="Bolton";
5
+
console.log(`I was born in ${cityOfBirth}`);
6
+
7
+
// The console.log was written before the variable was declared, so JavaScript didn't know what cityOfBirth was yet. Moving the declaration above the console.log fixes it.
@@ -11,12 +11,12 @@ console.log(`The percentage change is ${percentageChange}`);
11
11
12
12
// Read the code and then answer the questions below
13
13
14
-
// a) How many function calls are there in this file? Write down all the lines where a function call is made
14
+
// a) 5 function calls: replaceAll and Number on line 4, replaceAll and Number on line 5, console.log on line 10.
15
15
16
-
// 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?
16
+
// b) The error is on line 5. There is a comma missing between the two arguments of replaceAll, it should be replaceAll(",", "") not replaceAll("," "").
17
17
18
-
// c) Identify all the lines that are variable reassignment statements
18
+
// c) Lines 4 and 5 are variable reassignment statements.
19
19
20
-
// d) Identify all the lines that are variable declarations
20
+
// d) Lines 1, 2, 7, and 8 are variable declarations.
21
21
22
-
// e) Describe what the expression Number(carPrice.replaceAll(",","")) is doing - what is the purpose of this expression?
22
+
// e) Number(carPrice.replaceAll(",","")) removes the commas from the string using replaceAll, then Number() converts that string into an actual number so maths can be done with it.
0 commit comments