-
-
Notifications
You must be signed in to change notification settings - Fork 395
London | 26-ITP-May | Gideon Defar | Sprint 1 | Coursework #1553
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
3782ccb
6c946bc
38663ff
e2d0541
0420930
6c20163
9f7fab4
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -17,7 +17,6 @@ console.log(`The base part of ${filePath} is ${base}`); | |
| // Create a variable to store the dir part of the filePath variable | ||
| // Create a variable to store the ext part of the variable | ||
|
|
||
| const dir = ; | ||
| const ext = ; | ||
|
|
||
| const dir = filePath.slice(0, lastSlashIndex); | ||
| const ext = filePath.slice(lastDotIndex); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It looks like lastDotIndex has not been defined before it is used here. |
||
| // https://www.google.com/search?q=slice+mdn | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2,3 +2,5 @@ | |
|
|
||
| const age = 33; | ||
| age = age + 1; | ||
|
|
||
| // unlike let, const variables cannot be reassigned once created. | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,2 +1,5 @@ | ||
| const 12HourClockTime = "8:53pm"; | ||
| const 24hourClockTime = "20:53"; | ||
| const HourClockTime = "8:53pm"; | ||
| const hourClockTime = "20:53"; | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could we name these variables more consistently and make the time format clear in each name? |
||
|
|
||
| // Naming convention: In JavaScript, variable names cannot begin with a number. | ||
| // It would crash instantly with a syntax error: | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2,7 +2,8 @@ let carPrice = "10,000"; | |
| let priceAfterOneYear = "8,543"; | ||
|
|
||
| carPrice = Number(carPrice.replaceAll(",", "")); | ||
| priceAfterOneYear = Number(priceAfterOneYear.replaceAll("," "")); | ||
| //priceAfterOneYear = Number(priceAfterOneYear.replaceAll("," "")); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Generally it’s good practice to remove commented-out code once it’s no longer needed. It helps keep the code clean and makes it easier for others to read. |
||
| priceAfterOneYear = Number(priceAfterOneYear.replaceAll(",","")); | ||
|
|
||
| const priceDifference = carPrice - priceAfterOneYear; | ||
| const percentageChange = (priceDifference / carPrice) * 100; | ||
|
|
@@ -20,3 +21,18 @@ console.log(`The percentage change is ${percentageChange}`); | |
| // d) Identify all the lines that are variable declarations | ||
|
|
||
| // e) Describe what the expression Number(carPrice.replaceAll(",","")) is doing - what is the purpose of this expression? | ||
|
|
||
| /* | ||
| a) There are two functions Line 4 & 5: | ||
| for eg, The expression Number(carPrice.replaceAll(",","")) is doing the following: | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Take another look at the function calls in this file. How many function calls are there in total? |
||
| 1. carPrice.replaceAll(",","") - This removes any commas from the carPrice string. | ||
| 2. Number(...) - This converts the resulting string into a number. | ||
| b) The uncaught syntax error is coming from line 5. The error occurs because there is a missing comma in the replaceAll method. | ||
| It should be carPrice.replaceAll(",", "") instead of carPrice.replaceAll("," ""). To fix this, add the missing comma. | ||
| c) The variable reassignment statements are on lines 4 and 5, where carPrice and priceAfterOneYear are being reassigned to their numeric values. | ||
| d) The variable declarations are on lines 1 and 2, where carPrice and priceAfterOneYear are declared using the let keyword. | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. How would you categorise const declarations? Would you consider them variables, values or something else? |
||
|
|
||
| e) The purpose of the expression Number(carPrice.replaceAll(",", "")) is to convert a string representation of a number (with commas as thousands separators) into an actual number that can be used in mathematical operations. | ||
|
|
||
| Generally, the purpose of this expression is to convert a string representation of a number (with commas as thousands separators) into a actual number that can be used in mathematical operations. | ||
| */ | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could we keep the spacing around the + operators consistent here to improve readability?