Skip to content

Commit 102d89b

Browse files
committed
Brought suggested changes
1 parent 7b47ad2 commit 102d89b

4 files changed

Lines changed: 18 additions & 9 deletions

File tree

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

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
let carPrice = "10,000";
22
let priceAfterOneYear = "8,543";
33

4-
carPrice = Number(carPrice.replaceAll(",", ""));
5-
priceAfterOneYear = Number(priceAfterOneYear.replaceAll(",", ""));
4+
// I hope this RegExp is taht programming term
5+
carPrice = Number(carPrice.replace(/,/g, ""));
6+
priceAfterOneYear = Number(priceAfterOneYear.replace(/,/g, ""));
67

78
const priceDifference = carPrice - priceAfterOneYear;
89
const percentageChange = (priceDifference / carPrice) * 100;
@@ -13,8 +14,8 @@ console.log(`The percentage change is ${percentageChange}`);
1314

1415
// a) How many function calls are there in this file? Write down all the lines where a function call is made
1516
// There are 4 function calls.
16-
// In line 4: Number() and replaceAll() are function calls.
17-
// In line 5: Number() and replaceAll() are function calls.
17+
// In line 4: Number() and replace(/,/g, "") are function calls.
18+
// In line 5: Number() and replace(/,/g, "") are function calls.
1819
// Including console.log(), there are 5 function calls.
1920

2021
// 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?

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

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,11 @@ const pounds = paddedPenceNumberString.substring(
2222
// substring() method removes "3" from "399" and returns "99";
2323
// padEnd() method pads the "99" and the padding applied is from the end of this string.
2424
const pence = paddedPenceNumberString
25-
.substring(paddedPenceNumberString.length - 2)
26-
.padEnd(2, "0");
25+
.substring(paddedPenceNumberString.length - 2);
2726

2827

2928
// In the log, backticks are used to output template literals ${pounds} and ${pence} with added '£' sign.
30-
console.log(${pounds}.${pence}`);
29+
// console.log(`£${pounds}.${pence}`);
3130

3231
// This program takes a string representing a price in pence
3332
// The program then builds up a string representing the price in pounds
@@ -37,3 +36,11 @@ console.log(`£${pounds}.${pence}`);
3736

3837
// To begin, we can start with
3938
// 1. const penceString = "399p": initialises a string variable with the value "399p"
39+
40+
// We don't need .padEnd(2, "0");
41+
// However, using this function will simplify and work for all types of pence
42+
function toPounds(pence) {
43+
return "£" + Number(pence.slice(0, -1) / 100).toFixed(2);
44+
}
45+
46+
console.log(toPounds("9p")); // £0.09

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,4 +19,5 @@ What effect does calling the `prompt` function have?
1919
It opens a prompt asking for an input.
2020

2121
What is the return value of `prompt`?
22-
'myName
22+
The return value of `prompt` will be the output of whatever was written in the input of the prompt
23+
If the input is empty, '' will be returned

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ Try also entering `typeof console`
1616
Answer the following questions:
1717

1818
What does `console` store?
19-
It stores different data such as, debug, error, info, log, warn, and etc.
19+
It stores a temporary log of system messages, including errors, warnings, and informational output
2020

2121
What does the syntax `console.log` or `console.assert` mean? In particular, what does the `.` mean?
2222
`console.log` is a built-in function used to output messages or values in the console

0 commit comments

Comments
 (0)