-
-
Notifications
You must be signed in to change notification settings - Fork 339
London | 26-ITP-May | Zadri Abdule | Sprint 1 | Coursework #1300
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
7995c8d
5213e77
c77a3cf
ba118b5
d5dfe95
5c9289a
8f743b2
095d155
e054a32
6ea69f1
40825f8
5f00dde
265ee10
0463851
0d51c23
2f6b3d4
813fe73
0767a42
401518d
c8eacf0
5df9b40
94e1886
611b033
35a1a97
a4dbb5a
65b8d4b
f0bf490
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,16 @@ 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 | ||
|
|
||
| // Math.random() returns a random decimal number between 0 and 1 | ||
| // (maximum - minimum + 1) represents the size of range of numbers we want to include. We add +1 because both minim and maximum are included in the range | ||
| // Math.random() * (maximum - minimum + 1) gives us a random decimal between 0 and 100, but still decimal | ||
| // Math.floor() rounds down to the nearest whole number. So this. turns decimals like 99.9 into 99 | ||
| // + minimum since minimum = 1, this shifts the entire random range up by 1. so instead of 0-100, the range becomes 1-100 | ||
| // num should return a random integer between 1 and 100 | ||
|
Comment on lines
+12
to
+17
Contributor
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. Phrases like "a number between X and Y" are not precise enough in a program specification, because they do not clearly state whether the endpoints X and Y are included. One way to concisely and precisely describe a range of values is to use the math's interval notation:
For example, |
||
| 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? | ||
| We don't want the computer to run these 2 lines - how can we solve this problem? | ||
| // Using // to make them comments should resolve the problem. The // tells JavaScript to skip that line completely |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,12 @@ | ||
| // trying to create an age variable and then reassign the value by 1 | ||
|
|
||
| const age = 33; | ||
| age = age + 1; | ||
|
|
||
|
|
||
| let age = 33; | ||
|
|
||
| age++; // Increases age by 1 | ||
|
|
||
| console.log(age); // Output: 34 | ||
|
|
||
|
|
||
|
|
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,9 +1,13 @@ | ||
| const cardNumber = 4533787178994213; | ||
| const last4Digits = cardNumber.slice(-4); | ||
| const last4Digits = cardNumber.toString().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 | ||
|
|
||
| // I predict that the code will fail because .slice() is not valid on a number - The variable is a number, but .slice() only works on strings and arrays. | ||
| // The error that I got is similar to what I had predicted. |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,2 +1,13 @@ | ||
| const 12HourClockTime = "20:53"; | ||
| const 24hourClockTime = "08:53"; | ||
| // This line of code attempts to declare a constant variable named 12HourClockTime, but it results in a syntax error | ||
| const 24hourClockTime = "08:53"; | ||
|
|
||
| // While testing the code, the following error appeared in console: | ||
| // SyntaxError: Invalid or unexpected token | ||
|
|
||
| // Why did this error occur? according to the MDN Web Docs: https://developer.mozilla.org/en-US/docs , a "SyntaxError: Invalid or unexpected token" occurs when JavaScript encounters code that doesn't follow proper syntax rules | ||
| // In this case, the error happens because JavaScript does not allow variable names to start with numbers. Variable names (also called identifiers) must begin with a letter, underscore (_), or dollar sign ($) | ||
|
|
||
| // How to fix the error: | ||
| const hour12ClockTime = "20:53"; | ||
| // These version follow JavaScript naming rules and will execute without errors |
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.
Operation like
count = count + 1is very common in programming, and there is a programming term describing such operation.Can you find out what one-word programming term describes the operation on line 3?