-
-
Notifications
You must be signed in to change notification settings - Fork 337
Manchester | 26-ITP-Jan | Farancis Dore Etonkie |Sprint 1 |Structuring and testing data #1211
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
d3add85
e2cd279
854e79e
bc447ba
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,6 @@ | ||
| let count = 0; | ||
|
|
||
| count = count + 1; | ||
|
|
||
| // 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 | ||
| //This means that increase the count number by 1 (by adding 1 to the initial number) and maintain the count value after adding 1. E.g 0+1 =1, so the new count now will be 1. | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -7,3 +7,19 @@ 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 | ||
|
|
||
|
|
||
| //ANSWERS: | ||
| // Num represents a random whole number(integers). In which in this case it can be between 1 to 100. | ||
| //Now let me break it down; | ||
|
|
||
| //This const minimum = 1; and this const maximum = 100; represent the range from which i want my random numbers to come from. | ||
|
|
||
| //This command Math.random() generates a random decimal number from 0(being inclusive) to 1(but not inclusing 1) e.g 0.23, 0.87, 0.001 or 0.999 but it will never generate 1. | ||
|
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. Note: We can also use the concise and precise interval notation to describe a range of values.
For example, we can say |
||
| // This command (maximum - minimum + 1) is a calculation of the Maximum and Minimum number i.e, 100-1+1=100 | ||
| // This command Math.floor helps to remove any decimal point and round numbers down to the nearest whole number. e.g from 45.9 to 45 | ||
| // This command +Minimum helps to add the minimum number in our range inorder to increase the numbers to 100(incusive) | ||
|
|
||
| console.log (num) | ||
|
|
||
| //After logging and running num, I had these series of numbers: 12, 66, 36,64,9,91.... | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,2 +1,6 @@ | ||
| 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? | ||
|
|
||
| //Answer: | ||
|
|
||
| //By turning them into comments(by using //) just like this setence. |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,9 @@ | ||
| // trying to create an age variable and then reassign the value by 1 | ||
|
|
||
| const age = 33; | ||
| let age = 33; | ||
| age = age + 1; | ||
|
|
||
| console.log (age); | ||
|
|
||
|
|
||
| //I had to change the variable (const) to (let) because a value assigned to (const) can not be assign again, while with (let) it can be reassigned |
| 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}`); | ||
|
|
||
| //It is important to declare a variable before using it. |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,4 @@ | ||
| const cardNumber = 4533787178994213; | ||
| const cardNumber = "4533787178994213"; | ||
| const last4Digits = cardNumber.slice(-4); | ||
|
Comment on lines
-1
to
2
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. Suppose you were not allowed to modify the statement |
||
|
|
||
| // The last4Digits variable should store the last 4 digits of cardNumber | ||
|
|
@@ -7,3 +7,8 @@ const last4Digits = cardNumber.slice(-4); | |
| // 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 | ||
|
|
||
| console.log(last4Digits) | ||
|
|
||
|
|
||
| //The number attributed to the value cardNumber is not a String, so we need to make the make a string. | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,2 +1,7 @@ | ||
| const 12HourClockTime = "20:53"; | ||
| const 24hourClockTime = "08:53"; | ||
| const formatAs12HourClockTime = "20:53"; | ||
| const formatAs24hourClockTime = "08:53"; | ||
|
|
||
| console.log(formatAs12HourClockTime) | ||
| console.log(formatAs24hourClockTime) | ||
|
|
||
| //Variable names do not start with numbers. |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -12,14 +12,22 @@ 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? | ||
| // 6 variable declaration. Which are movieLength, remainingSeconds, totalMinutes, remainingMinutes, totalHours, result | ||
|
|
||
| // b) How many function calls are there? | ||
| // 1 functions, which is Console.log | ||
|
|
||
| // c) Using documentation, explain what the expression movieLength % 60 represents | ||
| // It represents the remainder expression. This means that the remainder operator returns the remainder left over when one operand is divided by a second operand. | ||
| // | ||
| // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Arithmetic_Operators | ||
|
|
||
| // d) Interpret line 4, what does the expression assigned to totalMinutes mean? | ||
| // This command calculate the number of hours in the expression then extract the leftover minutes. | ||
|
|
||
| // e) What do you think the variable result represents? Can you think of a better name for this variable? | ||
| // It creates a formated string. for example: 2:30:23. That is the movie duration formated in Hours:Minutes:Seconds. | ||
| //Better names could be; FormatedDuration or MovieDuration or FormatedTime. | ||
|
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. All names look good. Please note that in JS naming convention, variable names usually begins with a lowercase letter. Names starting with an uppercase letter are used for built-in and custom data types (e.g., |
||
|
|
||
| // f) Try experimenting with different values of movieLength. Will this code work for all values of movieLength? Explain your answer | ||
| // It would Works for positive integers only; not ideal for negatives, decimals, or proper formatting. | ||
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?