-
-
Notifications
You must be signed in to change notification settings - Fork 314
Glasgow | 26-ITP-Jan| Martin McLean | Sprint 1 | coursework #955
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
ebed26d
3f5aecf
a2714eb
fbdf964
a7ce6b5
90091fd
9ee2adf
0263d62
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,10 @@ | ||
| const minimum = 1; | ||
| const maximum = 100; | ||
| const minimum = 80; | ||
| const maximum = 83; | ||
|
|
||
| const num = Math.floor(Math.random() * (maximum - minimum + 1)) + minimum; | ||
|
|
||
| // In this exercise, you will need to work out what num represents? | ||
| // 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 | ||
| console.log(num); |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,2 +1,4 @@ | ||
| 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? | ||
|
|
||
| comment them out!*/ |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,7 @@ | ||
| // 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); | ||
|
|
||
| // it needed to be a variabal not a constant |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,5 @@ | ||
| // 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 constant was declared after the sentence that used it |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,9 +1,12 @@ | ||
| const cardNumber = 4533787178994213; | ||
| const cardNumber = "4533787178994213"; | ||
| const last4Digits = cardNumber.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 | ||
|
|
||
|
|
||
| //it will not work because the cardNumber is a number and not a string so it cant use the slice method |
|
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. The specific time period was not taken into account; it is recommended to conduct some conversion tests for different time periods. 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. 12:xx PM should still be 12:xx 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. another thing is 13.00 should use ":" not "." |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,2 +1,42 @@ | ||
| const 12HourClockTime = "20:53"; | ||
| const 24hourClockTime = "08:53"; | ||
| //const twelveHourClockTime = "20:53"; | ||
| //const twentyFourHourClockTime = "08:53"; | ||
|
|
||
| //variable names can't start with a number | ||
|
|
||
| // the times are in the wrong places ie:-20:53 is not a twelve hour time and as they are const they cant be directly changed | ||
|
|
||
| let twelveHourClockTime = "13:00"; | ||
| let twelthHour = twelveHourClockTime.substring( | ||
| 0, | ||
| twelveHourClockTime.length - 3 | ||
|
|
||
| ); | ||
|
|
||
| let sufix =".AM" | ||
|
|
||
|
|
||
| if (twelthHour >= 13) { | ||
| twelthHour = twelthHour - 12; | ||
| sufix =".PM" | ||
|
|
||
| } | ||
| let twelthMinutes = twelveHourClockTime.substring( | ||
| 2, | ||
| twelveHourClockTime.length | ||
| ); | ||
|
|
||
|
|
||
| let twentyFourHourClockTime = "04:59.am"; | ||
| let twentyFour = twentyFourHourClockTime.substring(0, | ||
| twentyFourHourClockTime.length -6) | ||
| twentyFour = parseInt(twentyFour); | ||
|
|
||
|
|
||
| if (twentyFourHourClockTime.match (/(pm|PM)/g)){ | ||
| twentyFour = twentyFour + 12; | ||
| } | ||
| let twentyFourMinuies = twentyFourHourClockTime.substring(2, twentyFourHourClockTime.length -3); | ||
|
|
||
|
|
||
| console.log(`${twelthHour}${twelthMinutes}${sufix}`); | ||
| console.log(`${twentyFour}${twentyFourMinuies}`); |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -12,14 +12,25 @@ 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? | ||
| // there are 6 declarations | ||
|
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. Which six? |
||
| // const movieLength | ||
| // const remainingSeconds | ||
| // const totalMinutes | ||
| // const remainingMinutes | ||
| // const totalHours | ||
| // const result | ||
|
|
||
| // b) How many function calls are there? | ||
|
|
||
| // 0 | ||
| // c) Using documentation, explain what the expression movieLength % 60 represents | ||
| // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Arithmetic_Operators | ||
| // it divides the first operand (number) by the second operand and returns the remainder | ||
|
|
||
| // d) Interpret line 4, what does the expression assigned to totalMinutes mean? | ||
| // line 4 subtracts the remaining seconds so the we can work with the whole Minutes | ||
|
|
||
| // e) What do you think the variable result represents? Can you think of a better name for this variable? | ||
| // result gives us a string literal with the results of the calculation perhaps a better name would be runLength or watchTime | ||
|
|
||
| // f) Try experimenting with different values of movieLength. Will this code work for all values of movieLength? Explain your answer | ||
| // i have went from high (2254:56:54) to low (0:1:24) and it seems to work for any number. | ||
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.
nice!
almost correct!
Please confirm that one of them is missing a "/"