Skip to content

Commit 0197521

Browse files
committed
Enhance comments for clarity and correctness on answers
1 parent d031689 commit 0197521

File tree

4 files changed

+20
-13
lines changed

4 files changed

+20
-13
lines changed

Sprint-1/1-key-exercises/4-random.js

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,9 @@ const num = Math.floor(Math.random() * (maximum - minimum + 1)) + minimum;
99
// Try logging the value of num and running the program several times to build an idea of what the program is doing
1010

1111
//Breakdown
12-
// Math.random() generates a random decimal number between 0 (inclusive) and 1 (exclusive).
12+
// Math.random() generates a random decimal number in the interval (0, 1).
1313
// (maximum - minimum + 1) calculates the range of numbers which is 100 - 1 + 1 = 100.
14-
// Multiplying Math.random() by (maximum - minimum + 1) scales the random decimal to a range of 0 (inclusive) to 100 (exclusive).
15-
// The Math.floor() rounds down the number to the nearest whole number, giving us an integer between 0 and 99.
16-
// Adding minimum (which is 1) shifts the range from 0-99 to 1-100.
14+
// Multiplying Math.random() by (maximum - minimum + 1) scales the random decimal to the interval [0, 100).
15+
// The Math.floor() rounds down the number to the nearest whole number, giving us an integer in [0, 99].
16+
// Adding minimum (which is 1) shifts the interval from [0, 99] to [1, 100].
17+
// Therefore, num is a random integer in the interval [1, 100].

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,9 @@ priceAfterOneYear = Number(priceAfterOneYear.replaceAll("," ""));
2727
// Line 5: replaceAll(",", "") and Number()
2828
// Line 9: console.log()
2929

30-
// b) The error is coming from line 4 and line 5.
31-
// The error occurs because the replaceAll method is being called on a string that contains a comma, which is not a valid number.
32-
// To fix this problem, we can remove the commas from the strings before converting them to numbers.
30+
// b) The error is coming from line 4 and line 5.
31+
// The error occurred because a comma was missing between the arguments while redefining priceAfterOneYear variable at line 4 and 24.(",", "")
32+
// To fix this problem, we need to put comma between the arguments or we can remove the commas from the strings before converting them to numbers.
3333

3434
// c) The variable reassignment statements are on line 4 and line 5, where carPrice and
3535
// priceAfterOneYear are being reassigned to the result of the Number() function.

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

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@ const pounds = paddedPenceNumberString.substring(
1111
paddedPenceNumberString.length - 2
1212
);
1313

14-
const pence = paddedPenceNumberString
15-
.substring(paddedPenceNumberString.length - 2)
16-
.padEnd(2, "0");
14+
const pence = paddedPenceNumberString.substring(
15+
paddedPenceNumberString.length - 2
16+
);
1717

1818
console.log(${pounds}.${pence}`);
1919

@@ -23,7 +23,6 @@ console.log(`£${pounds}.${pence}`);
2323
// You need to do a step-by-step breakdown of each line in this program
2424
// Try and describe the purpose / rationale behind each step
2525

26-
2726
//1. const penceString = "399p": initializes a string variable with the value "399p"
2827

2928
// 2 to 6.const penceStringWithoutTrailingP = penceString.substring(0,penceString.length - 1);
@@ -35,6 +34,13 @@ console.log(`£${pounds}.${pence}`);
3534
// 9.const pounds = paddedPenceNumberString.substring( 0, paddedPenceNumberString.length - 2);
3635
// gets the ammout of pounds by making a sub string that starts at the firts character (0) to the paddedPenceNumberString length -2 to exclued the last 2 characters (the p)
3736

38-
// 10.
37+
// 10.const pence = paddedPenceNumberString .substring(paddedPenceNumberString.length - 2);
38+
// Gets the amount of pence by making a substring that starts at the paddedPenceNumberString length -2 to get the last 2 characters
39+
3940
// 18.console.log(`£${pounds}.${pence}`);
4041
// gives the console the result using a string literal
42+
//console.log(`£${pounds}.${pence}`); :
43+
44+
// Combines the pounds and pence into a standard currency format and prints it to the console, "£3.99"
45+
// The program takes a string representing a price in pence (e.g., "399p")
46+
// and converts it to a string representing the price in pounds (e.g., "£3.99").

Sprint-1/4-stretch-explore/objects.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,4 +20,4 @@ Try also entering `typeof console`'object'
2020
Answer the following questions:What does `console` store?the console stores objects
2121
What does the syntax `console.log` or `console.assert` mean?
2222
In particular, what does the `.` mean?
23-
the . denotes what kind of object the console is being told to use and what to do with the data it has been given
23+
the . denotes what kind of object the console is being told to use and what to do with the data it has been given , the . operator called dot operator or property access operator and it is used to access properties or methods of an object.

0 commit comments

Comments
 (0)