-
-
Notifications
You must be signed in to change notification settings - Fork 241
London_Jan25| Sabita_Shrestha| Module-Structuring-and-Testing-Data| Sprint 3| Week 6 #337
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 all commits
05d1112
8651354
7e1a21b
9448fdf
097d88e
2a1f2de
5efd683
b96d284
0bf7256
feca213
9949ef4
2ec27d1
6d3d60a
aeec9cb
9a60b4f
09f5ade
cf45d3e
c713341
ad65d4e
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,3 @@ | ||
| 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? | ||
| // Buy using comments syntax which is 2 slash |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,6 @@ | ||
| // 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); | ||
| // I have change const to let, It won't let you to reassign, it will say error if we use 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}`); | ||
| // variable should declare before console.log. |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,9 +1,16 @@ | ||
| const cardNumber = 4533787178994213; | ||
| const last4Digits = cardNumber.slice(-4); | ||
|
|
||
| const cardNumber = 4533787178994213; | ||
| const last4Digits = String(cardNumber).slice(-4); // convert to string and extract last 4 digit | ||
| console.log(last4Digits); //print4213 | ||
| // 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 | ||
|
|
||
| //IN line 1 their was't any string that may be the reason. | ||
| //With out changing code its says TypeError | ||
|
|
||
| /* how would you modify the code (through type conversion) so that it can still extract the last 4 digits from its value. | ||
| To use slice() method we need to use string. | ||
|
|
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,2 +1,5 @@ | ||
| const 12HourClockTime = "20:53"; | ||
| const 24hourClockTime = "08:53"; | ||
| const twelveHourClockTime = "08:53"; | ||
| const twentyFourHourClockTime = "20:53"; | ||
| console.log(twelveHourClockTime); | ||
| console.log(twentyFourHourClockTime); | ||
| //it says syntax error because variable should start with letter or underscore. | ||
|
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. Well spotted. Can you see any other mistake in the code? |
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -5,21 +5,39 @@ const totalMinutes = (movieLength - remainingSeconds) / 60; | |
|
|
||
| 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? | ||
| // ans:There are 6 variable declaration which are const. | ||
|
|
||
| // b) How many function calls are there? | ||
| //ans: There is only 1 function call which is console.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: This is called remainder operator which divide the length of movie 8784 by 60 and place the remaining second which is 24. | ||
|
|
||
| // d) Interpret line 4, what does the expression assigned to totalMinutes mean? | ||
| // ans: It means movie length subtract the remaining seconds and use remainder operator like (8784-24=8760/60) which 146. | ||
| // Also, this line interpret the expression calculates total number of complete minutes in movieLength (which is in seconds). | ||
| //movieLength-remainingSecond | ||
| // remainingSEcond = movieLength % 60 | ||
|
|
||
| // e) What do you think the variable result represents? Can you think of a better name for this variable? | ||
| // anns: Better name for this variable will be "formattedMovieDuration" because it is more descriptive, clearly indicating that the value is a formatted string representing the movie's duration. | ||
|
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. Good choice of name 👍 |
||
|
|
||
| // f) Try experimenting with different values of movieLength. Will this code work for all values of movieLength? Explain your answer | ||
|
|
||
| const movieLength = 2080; // length of movie in seconds | ||
|
|
||
| const remainingSeconds = movieLength % 60; | ||
| const totalMinutes = (movieLength - remainingSeconds) / 60; | ||
|
|
||
| const remainingMinutes = totalMinutes % 60; | ||
| const totalHours = (totalMinutes - remainingMinutes) / 60; | ||
| const timeString = `${totalHours}:${remainingMinutes}:${remainingSeconds}`; | ||
| console.log(timeString); | ||
| // It does work with another value as i change the movie length, it does work. | ||
|
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 try with any other values? Can you think of any edge cases where the formatting might not work correctly? |
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -8,7 +8,11 @@ | |
| // Then, write the next test! :) Go through this process until all the cases are implemented | ||
|
|
||
| function getAngleType(angle) { | ||
| if (angle === 90) return "Right angle"; | ||
| if (angle === 90) return "Right angle" | ||
| if (angle < 90) return "Acute angle" | ||
| if (angle < 180) return "Obtuse angle" | ||
| if (angle === 180) return "Straight angle" | ||
| if (angle > 180) return "Reflex angle" | ||
| // read to the end, complete line 36, then pass your test here | ||
| } | ||
|
|
||
|
|
@@ -30,27 +34,41 @@ function assertEquals(actualOutput, targetOutput) { | |
| // Case 1: Identify Right Angles: | ||
| // When the angle is exactly 90 degrees, | ||
| // Then the function should return "Right angle" | ||
| test("should return 'Right angle' for angle 90", () => { | ||
| const right = getAngleType(90); | ||
| assertEquals(right, "Right angle"); | ||
| }); | ||
|
|
||
| // Case 2: Identify Acute Angles: | ||
| // When the angle is less than 90 degrees, | ||
| // Then the function should return "Acute angle" | ||
| test("should return 'Acute angle' for angle 45",() =>{ | ||
| const acute = getAngleType(45); | ||
| assertEquals(acute, "Acute angle"); | ||
|
|
||
| }); | ||
| // Case 3: Identify Obtuse Angles: | ||
| // When the angle is greater than 90 degrees and less than 180 degrees, | ||
| // Then the function should return "Obtuse angle" | ||
| test("should return 'Obtuse angle' for angle 120",() =>{ | ||
| const obtuse = getAngleType(120); | ||
| assertEquals(obtuse, "Obtuse angle"); | ||
| }); | ||
| // ====> write your test here, and then add a line to pass the test in the function above | ||
|
|
||
| // Case 4: Identify Straight Angles: | ||
| // When the angle is exactly 180 degrees, | ||
| // Then the function should return "Straight angle" | ||
| // ====> write your test here, and then add a line to pass the test in the function above | ||
|
|
||
| test("should return 'Straight angle' for angle 180",() =>{ | ||
| const straight = getAngleType(180); | ||
| assertEquals(straight, "Straight angle"); | ||
| }); | ||
| // Case 5: Identify Reflex Angles: | ||
| // When the angle is greater than 180 degrees and less than 360 degrees, | ||
|
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. Read this instruction carefully. Does the code check for exactly these conditions? |
||
| // Then the function should return "Reflex angle" | ||
| // ====> write your test here, and then add a line to pass the test in the function above | ||
| // ====> write your test here, and then add a line to pass the test in the function above | ||
| test("should return 'Reflex angle' for angle 200",() =>{ | ||
| const reflex = getAngleType(200); | ||
| assertEquals(reflex, "Reflex angle"); | ||
| }); | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -9,6 +9,8 @@ | |
|
|
||
| function isProperFraction(numerator, denominator) { | ||
| if (numerator < denominator) return true; | ||
| if (numerator > denominator) return false; | ||
| if (numerator === denominator) return false | ||
|
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. This code works, but is there a way to simplify it? |
||
| } | ||
|
|
||
| // here's our helper again | ||
|
|
@@ -25,6 +27,7 @@ function assertEquals(actualOutput, targetOutput) { | |
| // Input: numerator = 2, denominator = 3 | ||
| // target output: true | ||
| // Explanation: The fraction 2/3 is a proper fraction, where the numerator is less than the denominator. The function should return true. | ||
|
|
||
| const properFraction = isProperFraction(2, 3); | ||
| assertEquals(properFraction, true); | ||
|
|
||
|
|
@@ -40,13 +43,15 @@ assertEquals(improperFraction, false); | |
| // target output: true | ||
| // Explanation: The fraction -4/7 is a proper fraction because the absolute value of the numerator (4) is less than the denominator (7). The function should return true. | ||
| const negativeFraction = isProperFraction(-4, 7); | ||
| assertEquals(negativeFraction, true); | ||
| // ====> complete with your assertion | ||
|
|
||
| // Equal Numerator and Denominator check: | ||
| // Input: numerator = 3, denominator = 3 | ||
| // target output: false | ||
| // Explanation: The fraction 3/3 is not a proper fraction because the numerator is equal to the denominator. The function should return false. | ||
| const equalFraction = isProperFraction(3, 3); | ||
| assertEquals(equalFraction, false); | ||
| // ====> complete with your assertion | ||
|
|
||
| // Stretch: | ||
|
|
||
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.
Great 👍
You can also use e.g.
firstName[0]instead offirstName.charAt(0)- either option is fine.