-
-
Notifications
You must be signed in to change notification settings - Fork 387
CApe Town | May -ITP-26| Enice Mutanda|Sprint 1|Coursework #1386
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
7f49f8b
49f8a23
de0d814
edcff8e
6e2c969
89569c8
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,9 +1,19 @@ | ||
| const minimum = 1; | ||
| const maximum = 100; | ||
| const minimum = 3; | ||
| const maximum = 50; | ||
|
|
||
| const num = Math.floor(Math.random() * (maximum - minimum + 1)) + minimum; | ||
|
|
||
| // In this exercise, you will need to work out what num represents? | ||
| // the num is random number between 1 and 100. | ||
| // Try breaking down the expression and using documentation to explain what it means | ||
| // const minimum is a function expression | ||
| // = 1 is a minimum value assigned by the operator for the minimum | ||
| // = 100 is the maximum value assigned by the operator for the function. | ||
|
|
||
| // Method.floor generates a random number between 0 and 1 to nearest interger (whole number) | ||
| //Math.random generates a decimal number between 0 and 1 . | ||
|
|
||
| // 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 | ||
| console.log(num); | ||
| // I noticed that the different values change the print result . |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,2 +1,8 @@ | ||
| 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 don't want the computer to run these 2 lines - how can we solve this problem? | ||
|
|
||
|
|
||
| //his 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 use //to comment out the lines of code we don't want to run. |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,5 @@ | ||
| // trying to create an age variable and then reassign the value by 1 | ||
|
|
||
| const age = 33; | ||
| age = age + 1; | ||
| let age = 33; | ||
| age = 33 + 1; | ||
| console.log(age); |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,8 @@ | ||
| // 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}`); | ||
|
|
||
| // the error is that the variable cityOfBirth is being use in the console.log statement before it is declared with let or const unlike var. | ||
|
|
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,9 +1,26 @@ | ||
| const cardNumber = 4533787178994213; | ||
| const last4Digits = cardNumber.slice(-4); | ||
|
|
||
| // The last4Digits variable should store the last 4 digits of cardNumber | ||
| const last4Digits = String(cardNumber).slice(-4); | ||
|
|
||
|
|
||
| console.log(last4Digits); // "4213" | ||
|
|
||
|
|
||
| //.slice () works on arrays and strings | ||
|
|
||
|
|
||
| // 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. | ||
| // I ran the code the error i got was excatly as predicted. | ||
|
|
||
|
|
||
| // Consider: Why does it give this error? Is this what I predicted? If not, what's different? | ||
| // let prediction = " because of the lack of slice method available for numbers,I predict that the code will throw an error. | ||
| // the cardNumber variable is a number, and slice is a method that can only be used on strings or arrays."; | ||
| //slice is a method that can only be used on strings or arrays." // | ||
|
|
||
| // Then try updating the expression last4Digits is assigned to, in order to get the correct value | ||
|
|
||
| // The last4Digits variable should store the last 4 digits of cardNumber | ||
| console.log(last4Digits); // "4213" |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,2 +1,5 @@ | ||
| const 12HourClockTime = "8:53pm"; | ||
| const 24hourClockTime = "20:53"; | ||
| const twelveHourClockTime = "8:53pm"; | ||
| // the code having an error because the variable is not named correctly,has to be twelvehourclocktime instead of 12hourclocktime. | ||
| const twentyFourHourClockTime = "20:53"; | ||
| // the code having an error because the variable is not named correctly,has to be twentyfourhourclocktime insted of 24hourclocktime. | ||
|
|
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -7,19 +7,26 @@ const remainingMinutes = totalMinutes % 60; | |
| const totalHours = (totalMinutes - remainingMinutes) / 60; | ||
|
|
||
| const result = `${totalHours}:${remainingMinutes}:${remainingSeconds}`; | ||
| 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 variables in total: movieLength, remainingSeconds, totalMinutes, remainingMinutes, totalHours, result | ||
|
|
||
| // b) How many function calls are there? | ||
| // there are 3 function calls in line 4,7 and 9 | ||
|
|
||
| // c) Using documentation, explain what the expression movieLength % 60 represents | ||
| // 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? | ||
|
|
||
| // it means that the movie hour is being calculated. totalminutes minus remainingseconds divided by 60. | ||
| // e) What do you think the variable result represents? Can you think of a better name for this variable? | ||
|
|
||
| // the variable result represents the total length of the movie in hours and minutes. | ||
| //Better name is MOvieTime. | ||
|
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. Does the name movieTime give a good idea of how this new variable is different to the original movieLenght? |
||
| // f) Try experimenting with different values of movieLength. Will this code work for all values of movieLength? Explain your answer | ||
| // Yes, this code will work for all values because it is using the modulus operator to calculate the remaining seconds and is using division to calculate the total hours. | ||
| // The code will correctly handle any length of movie in seconds and convert it to the appropriate format. | ||
|
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. It may run without any errors, but does it always end up in the correct format? Are there any edge cases? |
||
|
|
||
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.
I think there are a few more function calls to find