-
-
Couldn't load subscription status.
- Fork 240
Manchester | 25-ITP-May | Mahtem T. Mengstu| Sprint 1 | Coursework/Sprint 1 #780
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 5 commits
d6c5c0b
2ae5aaa
ebd4d3e
7eb19b3
f683d85
76e6a40
b9a5530
fc1f2d4
927521c
7db8109
97637ad
5dab8a6
6e76b0d
6ac3015
1e97c2e
4010b4d
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,18 @@ 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 | ||
|
|
||
|
|
||
| // num represents the result of equation at the right hand side of the operator = | ||
|
|
||
| // Step-1 ---> Math.random() generates a random decimal, | ||
| // Step-2 ---> (maximum-minumum +1) is evaluated | ||
| // Step-3 ---> Math.random() is multiplied by (maximum-minumum +1) | ||
| // Step-4 ---> the resukt of Step-3 is round by the method Math.floor | ||
| // Step-5 ---> minimum is added to the result of Step-4 | ||
|
|
||
| // Thus, num represents random numbers generated between minimum 1 and maximum 100. As we run the code several times it | ||
|
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.
Remember, the aim of this is to ensure you're understanding the exercises. It's hard to do this if you don't write the answers in your own words 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. We've decided |
||
| // generates new numbers. | ||
|
|
||
|
|
||
| console.log(num); | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,2 +1,5 @@ | ||
| 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? | ||
|
|
||
| // We have solved it by adding two forward slashes (//) at the beginning of each line. | ||
| // The computer does not run this line too. |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,11 @@ | ||
| // trying to create an age variable and then reassign the value by 1 | ||
|
|
||
| const age = 33; | ||
| //const age = 33; | ||
|
|
||
| // we need to replace "const" with "let" | ||
|
||
|
|
||
| let age = 33; | ||
| age = age + 1; | ||
|
|
||
|
|
||
| console.log(age); | ||
| 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}`); | ||
| // The variable cityOfBirth was called before it was defined, so we need to bring that variable first | ||
| const cityOfBirth = "Bolton"; | ||
| console.log(`I was born in ${cityOfBirth}`); | ||
|
|
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,9 +1,20 @@ | ||
| const cardNumber = 4533787178994213; | ||
| const last4Digits = cardNumber.slice(-4); | ||
| //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 think the code does not work because cardNumber variable is not stored as string. | ||
|
|
||
| // My guess was right. | ||
|
|
||
| // Therefore first we need to change CardNumber variable into string before we use the slice method. |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,2 +1,14 @@ | ||
| const 12HourClockTime = "20:53"; | ||
| const 24hourClockTime = "08:53"; | ||
| const 24hourClockTime = "08:53"; | ||
|
|
||
| // Alternatively the above variable names can be corrected as follows: | ||
|
|
||
| // Option-1 | ||
|
|
||
| const twelveHourClockTime = "20:53"; | ||
| const twentyFourHourClockTime = "08:53"; | ||
|
|
||
| // Option -2 | ||
|
|
||
| const hour12ClockTime = "20:53"; | ||
| const hour24ClockTime = "08:53"; |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,4 @@ | ||
| const movieLength = 8784; // length of movie in seconds | ||
| const movieLength = -3500; // length of movie in seconds | ||
|
|
||
| const remainingSeconds = movieLength % 60; | ||
| const totalMinutes = (movieLength - remainingSeconds) / 60; | ||
|
|
@@ -13,13 +13,26 @@ console.log(result); | |
|
|
||
| // a) How many variable declarations are there in this program? | ||
|
|
||
| // Ans: There are 6 variable declaration: Line 1, Line 3, Line 4, Line 6, Line 7, Line 9, | ||
|
|
||
| // b) How many function calls are there? | ||
|
|
||
| // Ans: There is one function call ... log() | ||
|
|
||
| // c) Using documentation, explain what the expression movieLength % 60 represents | ||
| // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Arithmetic_Operators | ||
|
|
||
| // Ans: The expression movieLength % 60 returns the reminder after totalMinutes is divided by 60. | ||
|
||
|
|
||
| // d) Interpret line 4, what does the expression assigned to totalMinutes mean? | ||
|
|
||
| // The expression is calculating how many full minutes are in the movie’s total length by removing leftover seconds(less than 60) | ||
|
|
||
| // e) What do you think the variable result represents? Can you think of a better name for this variable? | ||
|
|
||
| // Ans: the variable result represent total movie lenght, Movie duration_hr_min_sec would be better name. | ||
|
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. In Javascript, the convention is to use "camel case". This would be perfect for a language like Python 🙂 Could you suggest one in camel case? See this article: link |
||
|
|
||
| // f) Try experimenting with different values of movieLength. Will this code work for all values of movieLength? Explain your answer | ||
|
|
||
| // Ans: I have tried with different values and it seems to work for all values, but it needs to validate to avoid entering negative values | ||
| // I inserted --3500 and returned 0: -58: -20 which does not mean real time representation. | ||
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 this be done using a template string?