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
// Predict and explain first BEFORE you run any code...
3
-
3
+
// the will be an error when this code runs because the retrun varaible has not been assigined by a value and there function has not declared a variable.
4
4
// this function should square any number but instead we're going to get an error
5
-
6
5
// =============> write your prediction of the error here
6
+
// synch equation
7
7
8
8
functionsquare(3){
9
9
returnnum*num;
10
10
}
11
11
12
12
// =============> write the error message here
13
+
// Uncaught SyntaxError: Unexpected number
14
+
// > return num * num;
15
+
// return num * num;
13
16
14
-
// =============> explain this error message here
17
+
//Uncaught SyntaxError: Illegal return statement
15
18
19
+
// =============> explain this error message here
20
+
// the error is simply saying that the return variable has not been assigned by a value.`illegal statement`.
Copy file name to clipboardExpand all lines: Sprint-2/2-mandatory-debug/2.js
+12-2Lines changed: 12 additions & 2 deletions
Original file line number
Diff line number
Diff line change
@@ -1,7 +1,8 @@
1
-
// Predict and explain first...
2
-
1
+
// Predict and explain first..
3
2
// Predict the output of the following code:
4
3
// =============> Write your prediction here
4
+
// i predict that the output will be 3 for all the numbers passed to the function because the function is not using the parameter
5
+
// passed to it instead it is using the variable num which is 103 so it will always return 3 as the last digit of any number passed to it.
5
6
6
7
constnum=103;
7
8
@@ -15,10 +16,19 @@ console.log(`The last digit of 806 is ${getLastDigit(806)}`);
15
16
16
17
// Now run the code and compare the output to your prediction
17
18
// =============> write the output here
19
+
// The last digit of 42 is 3
20
+
// The last digit of 105 is 3
21
+
// the last digit of 806 is 3
22
+
18
23
// Explain why the output is the way it is
19
24
// =============> write your explanation here
25
+
// The output is the way it is because the function getlastDigit is not using the parameter passed to it.instead it is using the variable num which is 103.
20
26
// Finally, correct the code to fix the problem
21
27
// =============> write your new code here
28
+
// the function getLastDigit(num){
29
+
// return num.string().slice(-1);}
22
30
23
31
// This program should tell the user the last digit of each number.
24
32
// Explain why getLastDigit is not working properly - correct the problem
33
+
// this is because the function getLastDigit is not using the parameter passed to it.
34
+
// instead it is using the variable num which is 103. so it will always return 3 as the last digit of any number passed to it.s
Copy file name to clipboardExpand all lines: Sprint-2/4-mandatory-interpret/time-format.js
+7Lines changed: 7 additions & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -22,17 +22,24 @@ function formatTimeDisplay(seconds) {
22
22
23
23
// a) When formatTimeDisplay is called how many times will pad be called?
24
24
// =============> write your answer here
25
+
// pad will be called 3 times, once for totalHours, once for remainingMinutes, and once for remainingSeconds.
25
26
26
27
// Call formatTimeDisplay with an input of 61, now answer the following:
27
28
28
29
// b) What is the value assigned to num when pad is called for the first time?
29
30
// =============> write your answer here
31
+
// The value assigned to num when pad is called for the first time is 0, which is the value of totalHours when the input is 61 seconds.
30
32
31
33
// c) What is the return value of pad is called for the first time?
32
34
// =============> write your answer here
35
+
// The return value of pad when it is called for the first time is "00", which is the padded string representation of totalHours (0) when the input is 61 seconds.
33
36
34
37
// d) What is the value assigned to num when pad is called for the last time in this program? Explain your answer
35
38
// =============> write your answer here
39
+
// The value assigned to num when pad is called for the last time in this program is 1, which is the value of remainingSeconds when the input is 61 seconds.
40
+
// This is because 61 seconds is equal to 1 minute and 1 second, so the remaining seconds after calculating total minutes and hours is 1.
36
41
37
42
// e) What is the return value of pad when it is called for the last time in this program? Explain your answer
38
43
// =============> write your answer here
44
+
// The return value of pad when it is called for the last time in this program is "01", which is the padded string representation of remainingSeconds (1)
0 commit comments