-
-
Notifications
You must be signed in to change notification settings - Fork 389
London | 26-ITP-May | Hugh Mills | Sprint 1 | Sprint 1 Coursework #1450
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
b0e374d
94908cd
bf72972
b08f2ed
385e8fd
16f8995
778229e
29cd03f
a3a586e
46f0a14
1540cdc
9078d72
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 |
|---|---|---|
|
|
@@ -2,8 +2,14 @@ const minimum = 1; | |
| const maximum = 100; | ||
|
|
||
| const num = Math.floor(Math.random() * (maximum - minimum + 1)) + minimum; | ||
| console.log (num); | ||
|
|
||
| // In this exercise, you will need to work out what num represents? | ||
| // 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 | ||
|
|
||
| // From what I can work out, it is generations a random number between 2 and 100 for the value of num. | ||
|
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.
Now can you think what will be the value of
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. from 0 to 1, mostly through decimals 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. Think like this Math.random() generates value in the range [0,1) where 0 is included and 1 is excluded. Since, Then
So for this line of code Adding |
||
| // math.floor ensures the number is a whole number without decibils. (maximum - minimu +1) is (100 - 1 + 1)=100. | ||
| // Math.random pics a random number from 0 to 1 with two decibils, such as 2.13. | ||
| // The Order they follow is: Match.random multiplied by (Maximum - minimum + 1), then add minimum of 1. | ||
| 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? | ||
| 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,6 @@ | ||
| // 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}`); | ||
|
|
||
|
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. what do you think, why it was not working before ?
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. Ah the order of them in line of code was wrong, const needs to be before the console.log. |
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,9 +1,14 @@ | ||
| const cardNumber = 4533787178994213; | ||
| const cardNumber = "4533787178994213"; | ||
|
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. This is correct but can you think of a way to convert a number to string using some js functions and use that to get the last 4 digit.
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. .toString wold work best I belive: 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. Here the last line would be like this :
|
||
| const last4Digits = cardNumber.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 | ||
| /* | ||
| 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 | ||
| I firsth thought the -4 would not work as it starts on 0 | ||
| I then recalled the code wont work as the cardNumber is a number and not a string, it needs to be a string for the .slice to work. | ||
| */ | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,2 +1,2 @@ | ||
| const 12HourClockTime = "8:53pm"; | ||
| const 24hourClockTime = "20:53"; | ||
| const _12HourClockTime = "8:53pm"; | ||
| const _24hourClockTime = "20:53"; |
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.
Apart from
count = count + 1, can you look for more compact operation to increment variable by 1.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.
could it be:
Let count = 0+1;
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.
No the are other approaches, when the requirement is to increase/decrease the value of a number only by 1.
You can go through this - increase-or-decrease-a-number-by-one