London | 26-ITP-May | Dipa Sarker | Sprint 1 | Coursework#1419
London | 26-ITP-May | Dipa Sarker | Sprint 1 | Coursework#1419Dipa-Sarker wants to merge 30 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.
| // 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 was a problem hiding this comment.
I think I made mistakes to write single line comment correctly. I made correction in the file.
There was a problem hiding this comment.
Thanks for looking at it again.
So I think you've got the objective of the section slightly wrong.
You obviously know what the problem is, as you have rightly explained.
However, the goal of the exercise is to apply that to the file.
i.e, Add the // to the start of each line.
There was a problem hiding this comment.
Oh sorry! I think now I get the point and made the correction properly.
| // 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?
There was a problem hiding this comment.
I think I have made the same mistakes to write single line comment correctly. I made correction in the file.
There was a problem hiding this comment.
Can we apply the fix to the problem? By changing line 2 to reflect your explanation.
There was a problem hiding this comment.
Can you please explain this again? I cannot understand your question.
There was a problem hiding this comment.
At the moment, if you run this, it will error out because we are trying to update a constant variable age. You've rightly explained the problem, and that we should let. What I was asking is to effect the change by updating line 2 to use let.
There was a problem hiding this comment.
Oh! now I got it and replace const with let. Also, I was confused about the rules of single line comment. That's why I put // at the end of each line. Now I made correction to all the files.
| // 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.
There was a problem hiding this comment.
I think I made same mistakes again to write single line comment correctly. I made correction in the file.
There was a problem hiding this comment.
Can we apply your explanation to this file?
I.e, move line 5 to maybe a different line?
There was a problem hiding this comment.
I moved the line 5 (variable declaration line) before console.log and now I can see the output "I was born in Bolton".
| 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?
There was a problem hiding this comment.
I thought the variable name could be "newcardNumber" or "formatcardNumber". I used "formatcardNumber".
There was a problem hiding this comment.
I thought the variable name could be "newCardNumber" or "formatCardNumber". I used "formatCardNumber".
|
|
||
| // 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 |
There was a problem hiding this comment.
Sorry for the typo. I made correction.
| // 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?
There was a problem hiding this comment.
yes, negative numbers work. I tried with const movieLength = -1515; & it gives result 0:-25:-15 but this is not our requirment.
| 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.
There was a problem hiding this comment.
highlighted all 4 variable declaration lines.
There was a problem hiding this comment.
Brilliant! You caught exactly what I wanted to see!
Previously, what you highlighted as variable reassignment weren't, but you have correctly identified them now. Very well done!
| // 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.
There was a problem hiding this comment.
Made corrections for variable reassignments.
| @@ -1,5 +1,9 @@ | |||
| // Currently trying to print the string "I was born in Bolton" but it isn't working... | |||
| // what's the error ? | |||
| // Currently trying to print the string "I was born in Bolton" but it isn't working... // | |||
There was a problem hiding this comment.
I noticed you added // at the end? Do we need it?
There was a problem hiding this comment.
I explained in the previous comment and made correction.
| // Currently trying to print the string "I was born in Bolton" but it isn't working... | ||
| // what's the error ? | ||
| // Currently trying to print the string "I was born in Bolton" but it isn't working... // | ||
| // what's the error ? // |
There was a problem hiding this comment.
I noticed you added // at the end? Do we need it?
|
|
||
|
|
||
| // 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.
I noticed you added // at the end? Do we need it?
| // 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 can solve this problem by writing those two lines as comments using // |
There was a problem hiding this comment.
I noticed you added // at the end? Do we need it?
| // 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? // |
There was a problem hiding this comment.
I noticed you added // at the end? Do we need it?
Learners, PR Template
Self checklist
Changelist