-
-
Notifications
You must be signed in to change notification settings - Fork 389
London | 26-ITP-May | Dipa Sarker | Sprint 1 | Coursework #1419
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
9cfc4d2
215069c
dd9a1ca
a102624
8e1e5ad
a0b416f
d26014e
cd349dc
c267bf0
324b237
f5499b3
5eb5f21
18b7731
2cb9c3a
6184479
94d7e29
376bf6e
a1fa80e
6364e1e
f50f93c
049a4e5
411f51a
98f8826
84b90f5
a16ebf1
b887977
ed5a33c
772f314
c1a8dc6
4795280
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,2 +1,5 @@ | ||
| 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? | ||
|
|
||
| // We can solve this problem by writing those two lines as comments using | ||
| // Because JavaScript ignores commented lines and they will not be executed by the computer. |
| 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; | ||
|
|
||
| // There is a constant variable age, which is fixed and it's value cannot be reassigned. | ||
| // If we want to change the value of age, we have to use let instead of const. |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,9 @@ | ||
| // Currently trying to print the string "I was born in Bolton" but it isn't working... | ||
| // what's the error ? | ||
| // 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 variable const cityOfBirth = "Bolton"; needs to be declared at first. | ||
| // As it is not declared, JavaScript cannot find out the variable cityofBirth in console.log. |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,9 +1,19 @@ | ||
| const cardNumber = 4533787178994213; | ||
| const last4Digits = cardNumber.slice(-4); | ||
| console.log(cardNumber.toString()); | ||
| const formatCardNumber = cardNumber.toString(); | ||
| const last4Digits = formatCardNumber.slice(-4); | ||
| console.log(last4Digits); | ||
|
Comment on lines
1
to
+5
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. Really clever solution, I really like it!
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. I thought the variable name could be "newcardNumber" or "formatcardNumber". I used "formatcardNumber".
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. I thought the variable name could be "newCardNumber" or "formatCardNumber". I used "formatCardNumber". 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. Much much better, well done! |
||
|
|
||
| // 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 | ||
| // I think slice () works for strings or arrays not for numbers. That's why the code won't work. | ||
| // Then run the code and see what error it gives. | ||
| // After running code TypeError: cardNumber.slice is not a function this error shows. | ||
| // 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 | ||
| // It gives this error because cardNumber doesn't have slice method. My prediction was beacuse | ||
| // cardNumber is number not string and the difference is that slice method called but it | ||
| // doesn't exist on that type. | ||
| // Then try updating the expression last4Digits is assigned to, in order to get the correct | ||
| // value | ||
| // Updated the expression in order to get in to the correct value. | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,2 +1,2 @@ | ||
| const 12HourClockTime = "8:53pm"; | ||
| const 24hourClockTime = "20:53"; | ||
| const twelveHourClockTime = "8:53pm"; | ||
| 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,29 @@ 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 | ||
| // There are 5 function calls. carPrice = Number(carPrice.replaceAll(",", "")); | ||
| // priceAfterOneYear = Number(priceAfterOneYear.replaceAll("," "")); | ||
| // In the above 2 lines, 2 replaceAll() functions for carPrice and priceAfterOneyear and after executing them again Number() | ||
| // functions for the 2 variables. | ||
| // At last, console.log() function for printing the executed value. | ||
|
|
||
| // 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? | ||
| // after running the code, the error is coming from this line priceAfterOneYear = Number(priceAfterOneYear.replaceAll("," ""));and | ||
| // the error is SyntaxError: missing ) after argument list. There is a comma missing in replaceAll() syntax. It should be | ||
| // priceAfterOneYear = Number(priceAfterOneYear.replaceAll(",", "")); | ||
|
|
||
| // c) Identify all the lines that are variable reassignment statements | ||
| // There are 2 variable reassignment statements. | ||
| // carPrice = Number(carPrice.replaceAll(",", "")); | ||
| // priceAfterOneYear = Number(priceAfterOneYear.replaceAll(",", "")); | ||
|
|
||
| // d) Identify all the lines that are variable declarations | ||
| // There are 4 variable declarations lines. | ||
| // let carPrice = "10,000"; | ||
| // let priceAfterOneYear = "8,543"; | ||
|
Comment on lines
+32
to
+34
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 highlight the lines where the declarations are?
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. highlighted all 4 variable declaration lines. 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. Brilliant! You caught exactly what I wanted to see! |
||
| // 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? | ||
| // Firstly this expression replace all the commas from the variable carPrice = "10,000" to "10000" and then it converts | ||
| // string "10,000" to number 10000. | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,4 @@ | ||
| const movieLength = 8784; // length of movie in seconds | ||
|
|
||
| const remainingSeconds = movieLength % 60; | ||
| const totalMinutes = (movieLength - remainingSeconds) / 60; | ||
|
|
||
|
|
@@ -12,14 +11,23 @@ console.log(result); | |
| // For the piece of code above, read the code and then answer the following questions | ||
|
|
||
| // a) How many variable declarations are there in this program? | ||
| // There are 6 variable declarations. | ||
|
|
||
| // b) How many function calls are there? | ||
| // There is one function call. | ||
|
|
||
| // c) Using documentation, explain what the expression movieLength % 60 represents | ||
| // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Arithmetic_Operators | ||
| // The expression movieLength % 60 divides the movieLength by 60 seconds and return the reminder | ||
| // which will be stroed in the const remainingSeconds. | ||
|
|
||
| // d) Interpret line 4, what does the expression assigned to totalMinutes mean? | ||
| // Firstly, Removes the leftover seconds from movieLength and then converts the remaining seconds | ||
| // into whole minutes which will be stored into totalMinutes. | ||
|
|
||
| // e) What do you think the variable result represents? Can you think of a better name for this variable? | ||
| // The variable result reprents the movieLength in hours:minutes:seconds. The variable should be renamed by totalDuration. | ||
|
|
||
| // f) Try experimenting with different values of movieLength. Will this code work for all values of movieLength? Explain your answer | ||
| // I have tried with 3 variables, 1515, 9999 & 70052. I observed that this code works succesfully with all the values | ||
|
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. Curious to see if a negative number will work.
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. yes, negative numbers work. I tried with const movieLength = -1515; & it gives result 0:-25:-15 but this is not our requirment. |
||
| // and gave me results for all the different movieLength in hours:minutes:seconds. | ||
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.
I really like how you have explained this.
Good job!