-
-
Notifications
You must be signed in to change notification settings - Fork 262
West Midlands | 25 Sep ITP | Iswat Bello | Sprint 1 | Module Structuring and Testing Data #744
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 14 commits
beda3cd
cdfcef0
d845bba
2c9afad
bbcddb9
5b0c0bc
0835346
2deec27
2f25058
4aaf415
b9f2f51
3090d19
03cb451
095a3ea
1030764
11a2c20
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,6 +1,11 @@ | ||
| let count = 0; | ||
|
|
||
| count = count + 1; | ||
| console.log(count); | ||
|
|
||
| // Line 1 is a variable declaration, creating the count variable with an initial value of 0 | ||
| // Describe what line 3 is doing, in particular focus on what = is doing | ||
|
|
||
| //Answer | ||
| // The third line is a statement that reassigns the value of count to count + 1. | ||
| // The assignment operator (=) updates the variable count with a new value. |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2,8 +2,32 @@ 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 | ||
|
|
||
| //Answers | ||
| // num is a constant variable that stores a random integer between the minimum and maximum values (inclusive), generated using Math.random() and Math.floor() | ||
|
|
||
|
|
||
|
|
||
| // Math.random() | ||
| // This expression gives you a random decimal number between 0 and 1. | ||
| // It could be something like 0.25 or 0.879, but it will never reach 1. | ||
|
|
||
| // (maximum - minimum + 1) | ||
| // This expression calculates how many numbers are in the range you want. | ||
| // For example, if your range is 1 to 100, the result is 100 because there are 100 possible values. | ||
|
|
||
| // Math.random() * (maximum - minimum + 1) | ||
| // This expression multiplies the random decimal by your range. | ||
|
|
||
|
|
||
| // Math.floor(...) | ||
| // This expression rounds the number down to the nearest integer. | ||
| // For example, 37.6 becomes 37, and 99.9 becomes 99. | ||
|
|
||
| // + minimum | ||
| // Variable minimum is added to the expression "Math.floor(Math.random() * (maximum - minimum + 1))" and the the value is stored inside the variable 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. Why do you think the variable minimum is added to the expression?
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. Hi @tenzyns. |
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,2 +1,11 @@ | ||
| 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? | ||
|
|
||
| // Interpretation: | ||
| // The error "SyntaxError: Unexpected identifier 'is'" means that JavaScript found the word "is", but it didn’t make sense in that position. | ||
| // It wasn’t valid code that JavaScript could understand. | ||
|
|
||
| // Why the error occurred: | ||
| // The error occurred because the sentence was written as plain text instead of a comment. | ||
| // To fix it, the sentence should be written as a comment (by adding // at the beginning) so that JavaScript ignores it. | ||
|
|
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,9 +1,22 @@ | ||
| const cardNumber = 4533787178994213; | ||
| const last4Digits = cardNumber.slice(-4); | ||
| // const cardNumber = 4533787178994213; | ||
| // 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 | ||
|
|
||
|
|
||
| // Answer | ||
| // The code will not work because the slice method in javascript only works on a string or an array. | ||
| // The data type of the value stored in the variable cardNumber is a number and for this reason, the code will return an error. | ||
| // After running the code, it gave an error " TypeError: cardNumber.slice is not a function" | ||
| // My prediction and the error align. | ||
| // To update the code, I will convert the variable cardNumber to a string first then use slice() method after | ||
|
|
||
| const cardNumber = 4533787178994213; | ||
| const last4Digits = cardNumber.toString().slice(-4); | ||
| console.log(last4Digits); |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,2 +1,12 @@ | ||
| const 12HourClockTime = "20:53"; | ||
| const 24hourClockTime = "08:53"; | ||
| // const 12HourClockTime = "20:53"; | ||
| // const 24hourClockTime = "08:53"; | ||
|
|
||
| // console.log(12HourClockTime , 24hourClockTime); | ||
|
|
||
| // Answer | ||
| // After running the code, it gave an error message "SyntaxError: Invalid or unexpected token". | ||
| // This error means that Javascript was unable to read the code because a variable name cannot start with a number | ||
| // I can fix this code by removing the numbers from the start of the variable name | ||
|
|
||
| const HourClockTime = "20:53"; | ||
|
||
| const hourClockTime = "08: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.
Here the aim is the store the ext part. if you look at the diagram, the ext part doesn't include the string 'file'. so how would you store just the ext part?
Uh oh!
There was an error while loading. Please reload this page.
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.
Hi @tenzyns.
Thank you for the feedback. I’ve updated the code to extract only the extension part by slicing from the last dot to the end and storing the value in the
extvariable. The updated code is shown below:const lastDotIndex = base.lastIndexOf(".");const ext = base.slice(lastDotIndex) ;