-
-
Notifications
You must be signed in to change notification settings - Fork 240
London | 25-ITP-September | Ammad Ur Rehman | Sprint 1 | 03 Complete Sprint 1 Coursework #785
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 18 commits
9a1b9a4
18a20f4
d428922
6a17974
6dbf419
c43a664
56a3e38
88aee46
ceae1cf
ea93025
1383234
8d02051
26947d3
8f9c9d3
f77fa4d
7659c5a
a4ffc85
3aa28fa
b4c662e
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 |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| { | ||
| "workspace.name" : "Module-Structuring-and-Testing-Data" | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,2 +1,4 @@ | ||
| 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? | ||
|
|
||
| // By commenting the lines |
| 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; | ||
|
|
||
| // You cannot mutate a constant so you need to change it to a variable where mutation is permitted |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,7 @@ | ||
| // 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}`); | ||
| const cityOfBirth = "Bolton"; | ||
| console.log(`I was born in ${cityOfBirth}`); | ||
|
|
||
| // The order of the code matters, the constant needs to be defined first before it can be used |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,9 +1,12 @@ | ||
| const cardNumber = 4533787178994213; | ||
| const last4Digits = cardNumber.slice(-4); | ||
| 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 | ||
|
|
||
| // slice() function only work on String type and not on Number type. | ||
| // So, convert the Number type into a String type in order to use slice() function |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,2 +1,4 @@ | ||
| const 12HourClockTime = "20:53"; | ||
| const 24hourClockTime = "08:53"; | ||
| const _12HourClockTime = "20:53"; | ||
| const _24hourClockTime = "08:53"; | ||
|
|
||
| // Variables and constants name cannot begin with a number but can include number later on |
| 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,17 @@ 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 | ||
| // Line 4, 5, 10 | ||
|
||
|
|
||
| // 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? | ||
| // It's missing a comma between the arguments at line 5 in replaceAll() method | ||
|
|
||
| // c) Identify all the lines that are variable reassignment statements | ||
| // Line 4, 5 | ||
|
|
||
| // d) Identify all the lines that are variable declarations | ||
| // Line 1, 2 | ||
|
|
||
| // e) Describe what the expression Number(carPrice.replaceAll(",","")) is doing - what is the purpose of this expression? | ||
| // Its purpose is to replace a substring with another string and then convert it into a number, in this case, replaces a command (",") with an empty string ("") | ||
| // In other words, remove the comma (",") in the string and then convert it into a number | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -12,7 +12,18 @@ invoke the function `alert` with an input string of `"Hello world!"`; | |
|
|
||
| What effect does calling the `alert` function have? | ||
|
|
||
| It displays an alert saying: | ||
|
|
||
| chrome://new-tab-page says | ||
|
|
||
| Hello world! | ||
|
|
||
| Now try invoking the function `prompt` with a string input of `"What is your name?"` - store the return value of your call to `prompt` in an variable called `myName`. | ||
|
|
||
| What effect does calling the `prompt` function have? | ||
|
|
||
| It displays an alert with a textfield where you can enter some text, e.g. John. | ||
|
|
||
| What is the return value of `prompt`? | ||
|
|
||
| The string returned from the textfield what the user has entered otherwise null if the user left it blank. | ||
|
||
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.
How do you figure it is [0, 1] and not [0, 1)?