-
-
Notifications
You must be signed in to change notification settings - Fork 336
Manchester | 26-ITP-JAN | Abdu Mussa | Sprint 1 | structuring and Testing Data #1058
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
884ddbe
bc09a5b
939f52f
540b62a
0db337a
86fc314
e412e75
445debd
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,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? */ | ||
|
|
||
| /*when we try to write comment and instruction and we want the computer not to run it we can comment them using // for single line and /* for multiple lines. */ |
| 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; | ||
| let age = 33; | ||
| age = age + 1; | ||
| // To reassign a value of age we have to use let not const. |
| 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}`); | ||
| const cityOfBirth = "Bolton"; | ||
| console.log(`I was born in ${cityOfBirth}`); | ||
|
|
||
| //the code try to log the variable before declaring the variable | ||
| // if we declare and initialize the variable first then we can use it. |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,2 +1,4 @@ | ||
| const 12HourClockTime = "20:53"; | ||
| const 24hourClockTime = "08:53"; | ||
| const hourClockTime12 = "20:53"; | ||
| const hourClockTime24 = "08:53"; | ||
|
|
||
| // Numbers are not allowed as the first character in naming of variables. |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -12,14 +12,23 @@ 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 variable declaration. | ||
|
|
||
| // b) How many function calls are there? | ||
| // there is only one function call. | ||
|
|
||
| // 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 represents the returns of the remainder after dividing one number by another | ||
| in this case 8784 % 60 and it return the remainder 24. */ | ||
|
|
||
| // d) Interpret line 4, what does the expression assigned to totalMinutes mean? | ||
| //This expression calculates the total full minutes in the movie by removing leftover seconds and converting seconds to minutes. | ||
|
|
||
| // e) What do you think the variable result represents? Can you think of a better name for this variable? | ||
| //result represent the total movie length using hours,minutes and seconds,the better name can be totalMovieLength. | ||
|
||
|
|
||
| // f) Try experimenting with different values of movieLength. Will this code work for all values of movieLength? Explain your answer | ||
| /*the code works for different values of movieLength it present the input movieLength by calculating the remainder and subtracting | ||
| it with the initial input and using the method for the finding of the value for the rest of the variables and assign the values withe | ||
| the variables of hours,minutes and seconds */ | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -24,4 +24,26 @@ console.log(`£${pounds}.${pence}`); | |
| // Try and describe the purpose / rationale behind each step | ||
|
|
||
| // To begin, we can start with | ||
| // 1. const penceString = "399p": initialises a string variable with the value "399p" | ||
| // 1. const penceString = "399p": initializes a string variable with the value "399p" | ||
|
|
||
| /* 2. const penceStringWithoutTrailingP = penceString.substring( | ||
| 0, | ||
| penceString.length - 1 | ||
| ); : this part of the code have two steps, | ||
| - inside assigning of variable there is a function call that replace the string "399p" by "399" | ||
| - then assigning the variable penceStringWithoutTrailingP with new string "399" */ | ||
|
|
||
| /* 3. const paddedPenceNumberString = penceStringWithoutTrailingP.padStart(3, "0"); this initializes new string value that have | ||
| 3 character if it's less than 3 it will add "0" in front of the string.*/ | ||
|
|
||
| /* 4. const pounds = paddedPenceNumberString.substring( | ||
| 0, | ||
| paddedPenceNumberString.length - 2 | ||
| ); : this part of the code assigning const pound with value of string that length is | ||
| reduced by -2 . */ | ||
|
|
||
| /* 5. const pence = paddedPenceNumberString | ||
| .substring(paddedPenceNumberString.length - 2) | ||
| .padEnd(2, "0"); : let's break it down this code parts it have two steps first one is .substring(paddedPenceNumberString.length - 2) | ||
| Takes the last 2 characters of the string and the second is .padEnd(2, "0") Ensures the result | ||
| is at least length 2 if the length less than 2 it will add 0 at the end of the string. */ | ||
|
Comment on lines
+44
to
+48
Contributor
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. Optional challenge:
Author
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. thank you for the feedback, we don't need the .padEnd(2, "0") in this script because the program will work for any valid penceString even after removing the padEnd.
Contributor
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. Did you figure out why
Author
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. yes i understood the concept before i didn't realise it ( which is even if we didn't put the pading there will be a value of 2 character and we don't need to have extra script. ) i also want to thank you because i learned more by the feedback i got from you.
Contributor
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. I am glad you understand the concept. |
||
Uh oh!
There was an error while loading. Please reload this page.