-
-
Notifications
You must be signed in to change notification settings - Fork 542
London | 26 ITP MAY | Russom Gebremeskel | Sprint 2 | Coursework #1502
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
2d1b73d
21df038
2753312
56c0cf5
148a95a
406e215
b9b3c99
a2f9b70
06cd821
05ec57a
a6af01c
e41c304
d3a57b0
c302bc4
e43b31e
9a013e1
439f732
ed79f77
28e7901
50b1516
209739c
a613e4c
fbade85
ee0394d
b3f5ce4
19404bf
47c46d3
59a3ca0
171051e
e0505a8
329b172
5a857cf
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 |
|---|---|---|
|
|
@@ -7,3 +7,10 @@ const num = Math.floor(Math.random() * (maximum - minimum + 1)) + minimum; | |
| // Try breaking down the expression and using documentation to explain what it means | ||
| // It will help to think about the order in which expressions are evaluated | ||
| // Try logging the value of num and running the program several times to build an idea of what the program is doing | ||
|
|
||
| // 1. num is a variable that stores the final result of the expression assigned to it. | ||
| // 2. The Math.random() method generates a random decimal number from 0 up but not excluding 1. | ||
|
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 be worth having another look at Math.random docs here. |
||
| // 3. The Math.floor() method round a decimal number down to a whole number. | ||
| // 4. (maximum - minimum + 1) calculates how many possible whole numbers there are. | ||
| // Java Script evaluates the expressions inside the inner parentheses first. | ||
| // + minimum adds 1 to move the range from 0 to the minimum 1. | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,2 +1,2 @@ | ||
| 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? |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,4 @@ | ||
| // trying to create an age variable and then reassign the value by 1 | ||
|
|
||
| const age = 33; | ||
| let age = 33; | ||
| age = age + 1; |
| 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}`); | ||
|
|
||
| // Java script cannot access the variable cityOfBirth before initialization. |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,9 +1,16 @@ | ||
| const cardNumber = 4533787178994213; | ||
| const last4Digits = cardNumber.slice(-4); | ||
| const last4Digits = Number(String(cardNumber).slice(-4)); | ||
|
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. Can you think of any edge cases that could surface here? |
||
|
|
||
| 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 | ||
|
|
||
| // Prediction: slice() is a string method. That is why it is not working on numbers. | ||
| // Error message: type error | ||
| // Convert the number to string | ||
| // If we need to keep number we need to convert it back from string to number using Number() method | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,2 +1,4 @@ | ||
| const 12HourClockTime = "8:53pm"; | ||
| const 24hourClockTime = "20:53"; | ||
| const twelveHourClockTime = "8:53pm"; | ||
| const twentyFourHourClockTime = "20:53"; | ||
|
|
||
| // Variable names cannot start with a number in Java Script. |
| 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,16 @@ 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? | ||
|
|
||
| // Answers | ||
|
|
||
| // a) There are no function or function calls in this code. | ||
|
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 are functions usually invoked in JS? |
||
|
|
||
| // b) The error was online 5 inside replaceAll method parentheses a comma is missing between the double quotes. | ||
|
|
||
| // c) Line 4 carPrice. Line 5 priceAfterOneYear. | ||
|
|
||
| // d) Line 1, 2, 7 and 8. | ||
|
|
||
| // e) The method replaceALL is removing the comma. Then the Number method is converting the string into numbers. | ||
| // The purpose is to use number operations and calculate the percentage change. | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -23,3 +23,17 @@ console.log(result); | |
| // e) What do you think the variable result represents? Can you think of a better name for this variable? | ||
|
|
||
| // f) Try experimenting with different values of movieLength. Will this code work for all values of movieLength? Explain your answer | ||
|
|
||
| // Answers | ||
|
|
||
| // a) There are 6 variable declarations. | ||
|
|
||
| // b) There are no function calls. | ||
|
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. Similar question to the one I left in previous file |
||
|
|
||
| // c) The reminder (%) operator returns the reminder left over when one operand is divided by a second operand. | ||
|
|
||
| // d) movieLength(8784) - remainingSeconds(24) = 8760(seconds). 8760 / 60 gives us 146 minutes. totalMInutes = 146 | ||
|
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. Nice! Great example of using real numbers to make explanation super clear. |
||
|
|
||
| // e) result represents the length of the movie in hours, minutes, and seconds format. It can be renamed movieDuration. | ||
|
|
||
| // f) When displaying single digit hour, minute, or seconds it doesn't include 0 in front of the digit. | ||
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.
Can you think of a more robust way to find extention?