-
-
Notifications
You must be signed in to change notification settings - Fork 337
Birmingham | ITP-Jan-26 | Ayodeji Ayorinde | Sprint 1 | Structuring and Testing Data #1128
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
Changes from 1 commit
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 |
|---|---|---|
|
|
@@ -6,6 +6,8 @@ let lastName = "Johnson"; | |
| // This should produce the string "CKJ", but you must not write the characters C, K, or J in the code of your solution. | ||
|
|
||
| let initials = ``; | ||
| initials = firstName.substring(0, 1) + middleName.substring(0, 1) + lastName.substring(0, 1) | ||
|
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. There are easier and more efficient ways to to extract a character at specific position/index in a string than using Can you find out what they are and update your code accordingly? |
||
| console.log(initials) | ||
|
|
||
| // https://www.google.com/search?q=get+first+character+of+string+mdn | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -17,7 +17,10 @@ console.log(`The base part of ${filePath} is ${base}`); | |
| // Create a variable to store the dir part of the filePath variable | ||
| // Create a variable to store the ext part of the variable | ||
|
|
||
| const dir = ; | ||
| const ext = ; | ||
| const dir = filePath.substring(0, 44); | ||
| console.log(`The dir part of the filePath variable is ${dir}`); | ||
|
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. Can you make these statements to work for any valid path? For example, they could still work correctly if we changed line 12 to |
||
|
|
||
| const lastDotIndex = filePath.lastIndexOf("."); | ||
| const ext = filePath.slice(lastDotIndex + 1); | ||
| console.log(`The ext of ${filePath} is ${ext}`); | ||
| // https://www.google.com/search?q=slice+mdn | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,2 +1,5 @@ | ||
| 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? | ||
|
|
||
| //ANSWER: | ||
| //We change the two lines to comments by using double forward slash (//) at the beginning of the two lines. |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2,3 +2,10 @@ | |
|
|
||
| const age = 33; | ||
| age = age + 1; | ||
|
|
||
| // ANSWER | ||
| // In the solution above, 'age' is a constant variable becuse the keyword 'const' was used with it hence the value cannot change. | ||
|
|
||
| // Solution: | ||
| let age = 33; | ||
| let age = age + 1; | ||
|
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. The solution is not quite correct. Have you tried running these two lines of code? |
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -7,3 +7,11 @@ const last4Digits = cardNumber.slice(-4); | |
| // 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 | ||
|
|
||
| //Predcition: slice() probably only work on string. Possible solution will be to put cardNumber in quotes or use String() | ||
| // Why does it give this error? It says 'cardNumber.slice is not a function' | ||
| // Is this what I predicted? No | ||
| // If not, what's different? Since cardNumber is numeric, it shoulf be changed to string fot slice() to work. | ||
|
|
||
| const cardNumber = "4533787178994213"; | ||
| const last4Digits = cardNumber.slice(-4); | ||
|
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. Suppose you were not allowed to modify the statement |
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,2 +1,11 @@ | ||
| const 12HourClockTime = "20:53"; | ||
| const 24hourClockTime = "08:53"; | ||
| const 24hourClockTime = "08:53"; | ||
|
|
||
| //In naming variable, numbers are not allowed to preceed variable names. | ||
|
|
||
| // Error message: An identifier or keyword cannot immediately follow a numeric literal. | ||
|
|
||
| // SUggested Solutions: | ||
|
|
||
| const ClockTime12Hour = "20:53"; | ||
| const ClockTime24hour = "08:53"; | ||
|
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. In JS naming convention, variable names usually begins with a lowercase letter. Names starting with an uppercase letter are used for built-in and custom data types (e.g., |
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -12,11 +12,12 @@ console.log(`The percentage change is ${percentageChange}`); | |
| // Read the code and then answer the questions below | ||
|
|
||
| // a) How many function calls are there in this file? Write down all the lines where a function call is made | ||
|
|
||
| //ANSWER: Four function calls. Two function calls in line 4 & two function calls in line 5 | ||
| // b) Run the code and identify the line where the error is coming from - why is this error occurring? How can you fix this problem? | ||
|
|
||
| //ANSWER: The comma in the replaceAll() function in Line 5 is missing. Put the comma back in to fix it. | ||
|
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. We can more precisely describe "A comma is missing between What is the programming term that belongs in the blank? |
||
| // c) Identify all the lines that are variable reassignment statements | ||
|
|
||
| //ANSWER: Lines that are variable reassignment statements are Lines 4 & 5. | ||
| // d) Identify all the lines that are variable declarations | ||
|
|
||
| //ANSWER: Variable declarations line: 1,2,7,& 8 | ||
| // e) Describe what the expression Number(carPrice.replaceAll(",","")) is doing - what is the purpose of this expression? | ||
| //ANSWER: The expression first removes the comma(,) in carPrice and then converts it to a number. | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -12,14 +12,15 @@ 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? | ||
|
|
||
| //ANSWER: There were six variable declarations | ||
| // b) How many function calls are there? | ||
|
|
||
| //ANSWER: There were no function calls except for the log() function | ||
| // c) Using documentation, explain what the expression movieLength % 60 represents | ||
| // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Arithmetic_Operators | ||
|
|
||
| //ANSWER: The remainder (%) operator returns the remainder left over when one operand is divided by a second operand. It always takes the sign of the dividend. | ||
| // d) Interpret line 4, what does the expression assigned to totalMinutes mean? | ||
|
|
||
| //ANSWER: Line 4 with find the remainder whenmovieLength is divided by 60 and assigns the remainder to remainingSeconds (24) | ||
| // e) What do you think the variable result represents? Can you think of a better name for this variable? | ||
|
|
||
| //ANSWER: The variable result represents the total lenth of the movie which shows the total hours, minutes and seconds remain in string format. | ||
|
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. Can you also answer the second question in Part (e)? |
||
| // f) Try experimenting with different values of movieLength. Will this code work for all values of movieLength? Explain your answer | ||
| //ANSWER: The code semed to work for all values of movieLength. | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -11,8 +11,15 @@ In the Chrome console, | |
| invoke the function `alert` with an input string of `"Hello world!"`; | ||
|
|
||
| What effect does calling the `alert` function have? | ||
| ## Got "chrome://new-tab-page says" popup | ||
| ## Hello world! | ||
|
|
||
| Now try invoking the function `prompt` with a string input of `"What is your name?"` - store the return value of your call to `prompt` in an variable called `myName`. | ||
|
|
||
| What effect does calling the `prompt` function have? | ||
| ## Got "chrome://new-tab-page says" popup | ||
| ## Got "What is your name?" | ||
| ## Got a box for input | ||
| What is the return value of `prompt`? | ||
| ## promt: ƒ prompt() { [native code] } | ||
| ## myName: Ayo | ||
|
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. What does the function return when a user clicks "Cancel" instead of "OK"? |
||
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.
Operation like
count = count + 1is very common in programming, and there is a programming term describing such operation.Can you find out what one-word programming term describes the operation on line 3?