London | 26-ITP-May | Dipa Sarker | Sprint 1 | Coursework#1419
London | 26-ITP-May | Dipa Sarker | Sprint 1 | Coursework#1419Dipa-Sarker wants to merge 14 commits into
Conversation
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
1 similar comment
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
| // num stores the result of the expression after calculating it. | ||
| // 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 | ||
| // There is a range of numbers from 1 to 100. In the expression, | ||
| // (maximum - minimum + 1) calculates the size of the possible integers, which is 100. | ||
| // The Math.random() function generates a random decimal number in the range 0 ≤ x < 1. | ||
| // This random decimal is then multiplied by the range size to scale it to a | ||
| // value between 0 and 100. The result is a floating-point number in this interval. | ||
| // Next, Math.floor() is used to round the number down to the largest integer less than | ||
| // or equal to the calculated value, producing an integer between 0 and 99. | ||
| // Finally, by adding minimum, the range is shifted from 0–99 to 1–100, giving a random | ||
| // integer within the required range. | ||
| // I have run 5 times the program and this produces different values each time because | ||
| // Math.random() generates a new random decimal number every time. | ||
| // Since the final value of num depends on this function, the result changes on each execution. No newline at end of file |
There was a problem hiding this comment.
I really like how you have explained this.
Good job!
|
|
||
| // We can solve this problem by writing those two lines as comments using //, | ||
| // because JavaScript ignores commented lines and they will not be executed by the computer. No newline at end of file |
There was a problem hiding this comment.
This is correct, but doesn't quite solve the problem. If we were to run this file as it is, what will happen? Will the code compile?
| // There is a constant variable age, which is fixed and it's value cannot be reassigned. | ||
| // If we want to change the value of age, we have to use let instead of const. No newline at end of file |
There was a problem hiding this comment.
Your explanation is correct, however If we were to run the code as it is, will the code compile successfully?
| // The variable const cityOfBirth = "Bolton"; needs to be declared at first. | ||
| // As it is not declared, JavaScript cannot find out the variable cityofBirth in console.log. No newline at end of file |
There was a problem hiding this comment.
Another great explanation, however we need to actually fix the problem.
| const cardNumber = 4533787178994213; | ||
| const last4Digits = cardNumber.slice(-4); | ||
| console.log(cardNumber.toString()); | ||
| const cardNumber1 = cardNumber.toString() | ||
| const last4Digits = cardNumber1.slice(-4); | ||
| console.log(last4Digits); |
There was a problem hiding this comment.
Really clever solution, I really like it!
Do you think we can find a better variable name for cardNumber1?
|
|
||
| // c) Using documentation, explain what the expression movieLength % 60 represents | ||
| // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Arithmetic_Operators | ||
| // The expression movieLength % 60 devides the movieLength by 60 seconds and return the reminder |
| // The variable result reprents the movieLength in hours:minutes:seconds. The variable should be renamed by totalDuration. | ||
|
|
||
| // f) Try experimenting with different values of movieLength. Will this code work for all values of movieLength? Explain your answer | ||
| // I have tried with 3 variables, 1515, 9999 & 70052. I observed that this code works succesfully with all the values |
There was a problem hiding this comment.
Curious to see if a negative number will work.
What do you think?
| invoke the function `alert` with an input string of `"Hello world!"`; | ||
|
|
||
| What effect does calling the `alert` function have? | ||
| // `alert` function deisplays a popup dialogue box with a message and the user have to click 'ok' button. |
There was a problem hiding this comment.
one small typo here: deisplays
| // There are 4 variable declarations lines. | ||
| // let carPrice = "10,000"; | ||
| // let priceAfterOneYear = "8,543"; |
There was a problem hiding this comment.
Could you please highlight the lines where the declarations are?
I.e line 1,10, 20.
| // const priceDifference = carPrice - priceAfterOneYear; | ||
| // const percentageChange = (priceDifference / carPrice) * 100; |
There was a problem hiding this comment.
Not quite. These lines are declarations, not reassignments. Have another look at what makes a statement a reassignment.
Learners, PR Template
Self checklist
Changelist