Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 398
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?
Uh oh!
There was an error while loading. Please reload this page.
Changes from all commits
3782ccb6c946bc38663ffe2d054104209306c201639f7fab41dc171d6ca968bfb2159a5879896c3c4171ec76eec5a3dacb063e8609e446ccFile filter
Filter by extension
Conversations
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Uh oh!
There was an error while loading. Please reload this page.
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,6 +1,10 @@ | ||
| let count = 0; | ||
| count = count + 1; | ||
| console.log(count); | ||
| // Line 1 is a variable declaration, creating the count variable with an initial value of 0 | ||
| // Describe what line 3 is doing, in particular focus on what = is doing | ||
| /* | ||
| Line 3 is an assignment operation. The right side evaluates first. | ||
| The assignment operator (=) then overwrites the old value with the new result. | ||
| */ |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,2 +1,3 @@ | ||
| This is just an instruction for the first activity - but it is just for human consumption | ||
| We don't want the computer to run these 2 lines - how can we solve this problem? | ||
| //This is just an instruction for the first activity - but it is just for human consumption | ||
| //We don't want the computer to run these 2 lines - how can we solve this problem? | ||
| //Answer: We add // to turn the text into comments |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,6 @@ | ||
| // trying to create an age variable and then reassign the value by 1 | ||
| const age = 33; | ||
| let age = 33; | ||
| age = age + 1; | ||
| // changed the variable from const (which cannot be reassigned) to let |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,12 @@ | ||
| // Currently trying to print the string "I was born in Bolton" but it isn't working... | ||
| // what's the error ? | ||
| console.log(`I was born in ${cityOfBirth}`); | ||
| // console.log(`I was born in ${cityOfBirth}`); | ||
gideondefar marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. | ||
| // const cityOfBirth = "Bolton"; | ||
| // ERROR: Cannot access 'cityOfBirth' before initialization console.log(`I was born in ${cityOfBirth}`); // ERROR: Cannot access 'cityOfBirth' before initialization | ||
| // Fixed: Swapped the line order to resolve the ReferenceError. | ||
| const cityOfBirth = "Bolton"; | ||
| console.log(`I was born in ${cityOfBirth}`); // SUCCESS: Variable is initialized first | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,9 +1,6 @@ | ||
| const cardNumber = 4533787178994213; | ||
| const last4Digits = cardNumber.slice(-4); | ||
| // 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 | ||
| const last4Digits = cardNumber.toString().slice(-4); | ||
| console.log(last4Digits); | ||
| // I thought the issue might be something to do with the number given (-4) but it's actually the fact that cardNumber.slice is not a function. | ||
| // Slice is not a function for numbers - it's for strings | ||
| // To solve this we can turn the card number into a string by using toString() - this converts the number to a string temporarily rather than changing the card number to a string itself. |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,2 +1,4 @@ | ||
| const 12HourClockTime = "8:53pm"; | ||
| const 24hourClockTime = "20:53"; | ||
| const clockTime12Hour = "8:53pm"; | ||
| const clockTime24Hour = "20:53"; | ||
| // 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,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; | ||
| @@ -20,3 +20,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 five functions Line 4, 5 and 10: | ||
| for eg, The expression Number(carPrice.replaceAll(",","")) is doing the following: | ||
gideondefar marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. | ||
| 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. | ||
gideondefar marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. | ||
| 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. | ||
| */ | ||
Uh oh!
There was an error while loading. Please reload this page.