-
-
Notifications
You must be signed in to change notification settings - Fork 301
JAN 25 London | MIKIYAS GEBREMICHAEL | STRUCTURING AND TESTING DATA | WEEK 1 #270
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
Changes from all commits
966ad14
bbea838
3af5e2e
cf3c37c
09000e2
186d23f
964e387
934d0c7
9d118b3
b3fe3d9
d44c433
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 |
|---|---|---|
| @@ -1,9 +1,17 @@ | ||
| const cardNumber = 4533787178994213; | ||
| const last4Digits = cardNumber.slice(-4); | ||
| const last4Digits = parseInt(cardNumber.toString().slice(-4)); | ||
| console.log(last4Digits); | ||
|
|
||
| // The last4Digits variable should store the last 4 digits of cardNumber | ||
| // However, the code isn't working | ||
| // Before running the code, make and explain a prediction about why the code won't work | ||
| // Then run the code and see what error it gives. | ||
| // Consider: Why does it give this error? Is this what I predicted? If not, what's different? | ||
| // Then try updating the expression last4Digits is assigned to, in order to get the correct value | ||
|
|
||
| //Answer | ||
| //i think it will give me the digits except the last 4 digits. | ||
| //the error is .slice is not a function. this is because it is only used with strings and arrays not numbers. | ||
| //so i have to change the format of the number to string by using .toString() | ||
| //now it will give the last 4 digits of our string. | ||
| //the last 4 digits are changed to number as suggested by mentor using by parseInt() |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,2 +1,9 @@ | ||
| const 12HourClockTime = "20:53"; | ||
| const 24hourClockTime = "08:53"; | ||
| const 24hourClockTime = "08: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. Please fix the error. There is another error present here. Please carefully compare the variable names to their respective values and see if you notice anything wrong.
Author
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. done |
||
| //Answer | ||
| //This is invalid syntax because variable names can not start with numbers | ||
| //instead we can say, twelveHourClockTime="20:53"; | ||
| /*fixed code below | ||
| const twelveHourClockTime="08:53 PM"; | ||
| const twentyFourHourClockTime="20:53"; | ||
| */ | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2,7 +2,7 @@ let carPrice = "10,000"; | |
| let priceAfterOneYear = "8,543"; | ||
|
|
||
| carPrice = Number(carPrice.replaceAll(",", "")); | ||
| priceAfterOneYear = Number(priceAfterOneYear.replaceAll("," "")); | ||
| priceAfterOneYear = Number(priceAfterOneYear.replaceAll(",", "")); | ||
|
|
||
| const priceDifference = carPrice - priceAfterOneYear; | ||
| const percentageChange = (priceDifference / carPrice) * 100; | ||
|
|
@@ -12,11 +12,30 @@ console.log(`The percentage change is ${percentageChange}`); | |
| // Read the code and then answer the questions below | ||
|
|
||
| // a) How many function calls are there in this file? Write down all the lines where a function call is made | ||
| // 4 , two in line 4 and 2 in line 5. | ||
| // Number() | ||
| // replaceAll() | ||
| // Number() | ||
| // replaceAll() | ||
|
|
||
| // 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? | ||
| // we have syntax error on line 5 and i have added , in side the bracket to separate "," and "". | ||
| // In line 5 it was this => priceAfterOneYear = Number(priceAfterOneYear.replaceAll("," "")); | ||
|
|
||
| // c) Identify all the lines that are variable reassignment statements | ||
| // line 4 and 5 are reassignments | ||
| //carPrice = Number(carPrice.replaceAll(",", "")); AND | ||
| //priceAfterOneYear = Number(priceAfterOneYear.replaceAll(",", "")); | ||
|
|
||
|
|
||
| // d) Identify all the lines that are variable declarations | ||
| // line 1,2,7 and 8 are variable declarations. | ||
| //let carPrice = "10,000"; | ||
| //let priceAfterOneYear = "8,543"; | ||
| //const priceDifference = carPrice - priceAfterOneYear; | ||
| //const percentageChange = (priceDifference / carPrice) * 100; | ||
|
|
||
| // e) Describe what the expression Number(carPrice.replaceAll(",","")) is doing - what is the purpose of this expression? | ||
| //it is replacing the characters in the string specified in the bracket to make them numbers. | ||
|
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 you please be just a little bit more specific? Not too in-depth, but be more specific about the details of the function.
Author
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. done |
||
| //example in --- let carPrice = "10,000"; ---carPrice = Number(carPrice.replaceAll(",", "")); | ||
| //we replace , and "" from carPrice and store the numeric value of 10000 | ||
Uh oh!
There was an error while loading. Please reload this page.