Skip to content

Commit 181a0db

Browse files
completed the tasks on interpret and stretch
1 parent 719ac38 commit 181a0db

5 files changed

Lines changed: 53 additions & 14 deletions

File tree

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

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,12 @@ console.log(`The percentage change is ${percentageChange}`);
1212
// Read the code and then answer the questions below
1313

1414
// a) How many function calls are there in this file? Write down all the lines where a function call is made
15-
15+
// 5 function calls: Number(...), replaceAll(",", ""), replaceAll("," ""), Number(...), console.log(...)
1616
// 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?
17-
17+
// The error is occurring on line 5 because there is a missing comma in the replaceAll method. The correct syntax should be replaceAll(",", "").
1818
// c) Identify all the lines that are variable reassignment statements
19-
19+
// 2 variable reassignment statements: line 4 and line 5
2020
// d) Identify all the lines that are variable declarations
21-
21+
// 4 variable declarations: line 1, line 2, line 7, line 8
2222
// e) Describe what the expression Number(carPrice.replaceAll(",","")) is doing - what is the purpose of this expression?
23+
// The expression Number(carPrice.replaceAll(",", "")) is first using the replaceAll method to remove all commas from the carPrice string, resulting in a string that represents a number without any formatting. Then, the Number function is used to convert that string into a numeric value. The purpose of this expression is to convert the formatted string representation of the car price into a usable numeric value for calculations.

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

Lines changed: 37 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,47 @@ 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-
15+
// 6 variable declarations: movieLength, remainingSeconds, totalMinutes, remainingMinutes, totalHours, result
1616
// b) How many function calls are there?
17-
17+
// only one function call: console.log(result);
1818
// c) Using documentation, explain what the expression movieLength % 60 represents
1919
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Arithmetic_Operators
20+
// The expression movieLength % 60 calculates the remainder of the division of movieLength by 60, which gives the number of seconds remaining after converting the total length of the movie from seconds to minutes.
2021

2122
// d) Interpret line 4, what does the expression assigned to totalMinutes mean?
22-
23+
// line 4 calculates the total number of minutes in the movie by subtracting the remaining seconds from the total movie length in seconds and then dividing that value by 60, thus converting the total length of the movie from seconds to minutes.
2324
// e) What do you think the variable result represents? Can you think of a better name for this variable?
24-
25+
// The variable result represents the total length of the movie in hours, minutes, and seconds format. A better name for this variable could be movieDuration or formattedMovieLength, as it more clearly describes the purpose of the variable.
2526
// f) Try experimenting with different values of movieLength. Will this code work for all values of movieLength? Explain your answer
27+
/* for positive integers:movieLength = 8784 → 2:26:24
28+
29+
movieLength = 60 → 0:1:0
30+
31+
movieLength = 3599 → 0:59:59
32+
33+
movieLength = 0 → 0:0:0
34+
35+
for negative integers: movieLength = -60 -> -1:59:0
36+
movieLength = -3599 -> -1:0:1
37+
movieLength = -8784 -> -3:33:36
38+
it works for negative integers as well, but the output may not be meaningful or should have validation to prevent negative values.
39+
40+
for non-integer values or decimal values: movieLength = 60.5 → 0:1:0.5
41+
movieLength = 3599.9 → 0:59:59.9
42+
movieLength = 8784.7 → 2:26:24.7
43+
it works for non-integer values as well, but the output may not be meaningful or should have validation to prevent non-integer values.
44+
45+
for non-numeric values: movieLength = "abc" → NaN:NaN:NaN
46+
movieLength = null → 0:0:0
47+
movielength = undefined → NaN:NaN:NaN
48+
it doesn't work for non-numeric values.
49+
50+
for very large values: movieLength = 1000000000 → 277777:46:40
51+
movieLength = 1000000000000 → 277777777:46:40
52+
it works for very Large values as well, but the output may not be meaningful or should have validation to prevent very Large values.
53+
54+
for very small values: movieLength = 0.0001 → 0:0:0
55+
movieLength = -0.0001 → 0:0:0
56+
movieLength = 0.0000001 → 0:0:0
57+
it works for very small values as well, but the output may not be meaningful or should have validation to prevent very small values.
58+

‎Sprint-2/3-mandatory-interpret/3-to-pounds.js‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,13 @@ const penceString = "399p";
22

33
const penceStringWithoutTrailingP = penceString.substring(
44
0,
5-
penceString.length - 1
5+
penceString.length - 1,
66
);
77

88
const paddedPenceNumberString = penceStringWithoutTrailingP.padStart(3, "0");
99
const pounds = paddedPenceNumberString.substring(
1010
0,
11-
paddedPenceNumberString.length - 2
11+
paddedPenceNumberString.length - 2,
1212
);
1313

1414
const pence = paddedPenceNumberString

‎Sprint-2/4-stretch-explore/chrome.md‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,10 @@ Let's try an example.
88
In the Chrome console, invoke the function `alert` with one argument, the string `"Hello world!"`;
99

1010
What effect does calling the `alert` function have?
11-
11+
a pop-up box with a message of HELLO WORLD on the window
1212
Now try invoking the function `prompt` with a string input of `"What is your name?"` - store the return value of your call to `prompt` in an variable called `myName`.
1313

1414
What effect does calling the `prompt` function have?
15+
the effect propmt displayed on the window is a pop-up box with an empty field to fill and with the string on top of it and when a user filled the field in. The filled in value gets displayed on the console.
1516
What is the return value of `prompt`?
17+
// the return value of the prompt as explained above is the answer or the value the user puts in the prompted field on the window.

‎Sprint-2/4-stretch-explore/objects.md‎

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,15 @@ In this activity, we'll explore some additional concepts that you'll encounter i
55
Open the Chrome devtools Console, type in `console.log` and then hit enter
66

77
What output do you get?
8-
8+
ƒ log() { [native code] }
99
Now enter just `console` in the Console, what output do you get back?
10-
10+
with a dropdown menu icon next to console {debug: ƒ, error: ƒ, info: ƒ, log: ƒ, warn: ƒ, …}
1111
Try also entering `typeof console`
12-
12+
'object'
1313
Answer the following questions:
1414

1515
What does `console` store?
16+
console is a regular javascript object provided by the browser or node and stores functions and/or properties.
17+
As the dot next to it is a property accessor on an object, console is an object that is built to store functions.
1618
What does the syntax `console.log` or `console.assert` mean? In particular, what does the `.` mean?
19+
The "." is a property access on the object and means get something inside this object.

0 commit comments

Comments
 (0)