-
-
Couldn't load subscription status.
- Fork 240
Manchester | 25-ITP-May | Mahtem T. Mengstu| Sprint 1 | Coursework/Sprint 1 #780
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 15 commits
d6c5c0b
2ae5aaa
ebd4d3e
7eb19b3
f683d85
76e6a40
b9a5530
fc1f2d4
927521c
7db8109
97637ad
5dab8a6
6e76b0d
6ac3015
1e97c2e
4010b4d
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,6 +1,55 @@ | ||
| let count = 0; | ||
| //let count = 0; | ||
|
|
||
| count = count + 1; | ||
| //count = count + 1; | ||
|
|
||
| // Line 1 is a variable declaration, creating the count variable with an initial value of 0 | ||
| // Describe what line 3 is doing, in particular focus on what = is doing | ||
| // Line 3 returns the incremented value of count. The operator = assigns count +1 to the varibale count in the | ||
| // left. | ||
|
|
||
| // Described what line three is doing. | ||
|
|
||
| // Example from codewar (from programming workshop) | ||
|
|
||
| function drawStairs(n) { | ||
| let result = ""; | ||
| if (n < 1) return result; // nothing to do | ||
|
|
||
| let iCount = 0; | ||
| while (iCount < n) { | ||
| // add spaces before the I (for all lines after the first) | ||
| let spaceCount = 0; | ||
| while (spaceCount < iCount) { | ||
| result = result.concat(" "); | ||
| spaceCount = spaceCount + 1; | ||
| } | ||
|
|
||
| // add the "I" | ||
| result = result.concat("I"); | ||
|
|
||
| // add a newline after each line except the last one | ||
| if (iCount < n - 1) { | ||
| result = result.concat("\n"); | ||
| } | ||
|
|
||
| // update the count | ||
| iCount = iCount + 1; | ||
| } | ||
|
|
||
| return result; | ||
| } | ||
|
|
||
| console.log(drawStairs(10)); | ||
|
|
||
| /// Another example | ||
|
|
||
| function drawStairs(n) { | ||
| let result = []; | ||
|
|
||
| for (let i = 0; i < n; i++) { | ||
| result[i] = `${' '.repeat(i)}I`; | ||
| } | ||
|
|
||
| return result.join('\n'); | ||
| } | ||
| console.log(drawStairs(5)); |
| 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? | ||
|
|
||
| // We have solved it by adding two forward slashes (//) at the beginning of each line. | ||
| // The computer does not run this line too. |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,14 @@ | ||
| // trying to create an age variable and then reassign the value by 1 | ||
|
|
||
| const age = 33; | ||
| //const age = 33; | ||
|
|
||
| // we need to replace "const" with "let", in javascript "const" is usd for variable | ||
| // that will nor change / will be kept constant troughout the code, where is "let" | ||
| // lets us to reassign variable later as we have done in the lines below the variabel age | ||
| // gets updated by one... | ||
|
|
||
| let age = 33; | ||
| age = age + 1; | ||
|
|
||
|
|
||
| console.log(age); |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,9 @@ | ||
| // 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}`); | ||
| // The variable cityOfBirth was called before it was defined, so we need to bring that variable first | ||
| const cityOfBirth = "Bolton"; | ||
| console.log(`I was born in ${cityOfBirth}`); | ||
|
|
||
| // Problem has been fixed | ||
|
|
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,9 +1,20 @@ | ||
| const cardNumber = 4533787178994213; | ||
| const last4Digits = cardNumber.slice(-4); | ||
| //const last4Digits = cardNumber.slice(-4); | ||
|
|
||
| const last4Digits = cardNumber.toString().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 | ||
|
|
||
| // I think the code does not work because cardNumber variable is not stored as string. | ||
|
|
||
| // My guess was right. | ||
|
|
||
| // Therefore first we need to change CardNumber variable into string before we use the slice method. |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,2 +1,14 @@ | ||
| const 12HourClockTime = "20:53"; | ||
| const 24hourClockTime = "08:53"; | ||
| const 24hourClockTime = "08:53"; | ||
|
|
||
| // Alternatively the above variable names can be corrected as follows: | ||
|
|
||
| // Option-1 | ||
|
|
||
| const twelveHourClockTime = "20:53"; | ||
| const twentyFourHourClockTime = "08:53"; | ||
|
|
||
| // Option -2 | ||
|
|
||
| const hour12ClockTime = "20:53"; | ||
| const hour24ClockTime = "08:53"; |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,4 @@ | ||
| const movieLength = 8784; // length of movie in seconds | ||
| const movieLength = -3500; // length of movie in seconds | ||
|
|
||
| const remainingSeconds = movieLength % 60; | ||
| const totalMinutes = (movieLength - remainingSeconds) / 60; | ||
|
|
@@ -13,13 +13,35 @@ console.log(result); | |
|
|
||
| // a) How many variable declarations are there in this program? | ||
|
|
||
| // Ans: There are 6 variable declaration: Line 1, Line 3, Line 4, Line 6, Line 7, Line 9, | ||
|
|
||
| // b) How many function calls are there? | ||
|
|
||
| // Ans: There is one function call ... log() | ||
|
|
||
| // c) Using documentation, explain what the expression movieLength % 60 represents | ||
| // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Arithmetic_Operators | ||
|
|
||
| // Ans: The expression movieLength % 60 returns the remainder after totalMinutes is divided by 60. | ||
|
|
||
| // d) Interpret line 4, what does the expression assigned to totalMinutes mean? | ||
|
|
||
| // The expression is calculating how many full minutes are in the movie’s total length by removing leftover seconds(less than 60) | ||
|
|
||
| // e) What do you think the variable result represents? Can you think of a better name for this variable? | ||
|
|
||
| // Ans: the variable result represent total movie lenght, Movie duration_hr_min_sec would be better name. | ||
|
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 Javascript, the convention is to use "camel case". This would be perfect for a language like Python 🙂 Could you suggest one in camel case? See this article: link |
||
|
|
||
| // In a "camel case" the following options would be better names | ||
| // 1. MovieDurationHrMinSec | ||
| // 2. TotalMovieSpan | ||
| // 3. TotalMoviePeriod | ||
|
||
|
|
||
| // f) Try experimenting with different values of movieLength. Will this code work for all values of movieLength? Explain your answer | ||
|
|
||
| // Ans: I have tried with different values and it seems to work for all values, but it needs to validate to avoid entering negative values | ||
| // I inserted --3500 and returned 0: -58: -20 which does not mean real time representation. | ||
|
|
||
|
|
||
| // Corrected typo reminder -----> remainder | ||
| // Suggested better names in "camel case" a convention in Javascript | ||
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.
Thus,suggests to me this might've been generated by AIRemember, the aim of this is to ensure you're understanding the exercises. It's hard to do this if you don't write the answers in your own words
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.
We've decided
Thusis not a good indicator of AI 👀