-
-
Notifications
You must be signed in to change notification settings - Fork 389
CApe Town | May -ITP-26| Enice Mutanda|Sprint 1|Coursework #1386
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
Open
Enice-Codes
wants to merge
7
commits into
CodeYourFuture:main
Choose a base branch
from
Enice-Codes:coursework/sprint-1
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
7f49f8b
completed sprint key excercises
49f8a23
completed all three excerises in this sprint
de0d814
completed key errors excercise 2
edcff8e
completed js excercises
6e2c969
Remove unintended app.js
89569c8
Remove Sprint-2 file from Sprint-1 PR
4c9c274
Renamed ,Corrected code
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,9 +1,19 @@ | ||
| const minimum = 1; | ||
| const maximum = 100; | ||
| const minimum = 3; | ||
| const maximum = 50; | ||
|
|
||
| const num = Math.floor(Math.random() * (maximum - minimum + 1)) + minimum; | ||
|
|
||
| // In this exercise, you will need to work out what num represents? | ||
| // the num is random number between 1 and 100. | ||
| // Try breaking down the expression and using documentation to explain what it means | ||
| // const minimum is a function expression | ||
| // = 1 is a minimum value assigned by the operator for the minimum | ||
| // = 100 is the maximum value assigned by the operator for the function. | ||
|
|
||
| // Method.floor generates a random number between 0 and 1 to nearest interger (whole number) | ||
| //Math.random generates a decimal number between 0 and 1 . | ||
|
|
||
| // 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); | ||
| // I noticed that the different values change the print result . |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,2 +1,8 @@ | ||
| 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? | ||
|
|
||
|
|
||
| //his 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 can use //to comment out the lines of code we don't want to run. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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; | ||
| age = age + 1; | ||
| let age = 33; | ||
| age = 33 + 1; | ||
| console.log(age); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,8 @@ | ||
| // 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 error is that the variable cityOfBirth is being use in the console.log statement before it is declared with let or const unlike var. | ||
|
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,9 +1,26 @@ | ||
| const cardNumber = 4533787178994213; | ||
| const last4Digits = cardNumber.slice(-4); | ||
|
|
||
| // The last4Digits variable should store the last 4 digits of cardNumber | ||
| const last4Digits = String(cardNumber).slice(-4); | ||
|
|
||
|
|
||
| console.log(last4Digits); // "4213" | ||
|
|
||
|
|
||
| //.slice () works on arrays and strings | ||
|
|
||
|
|
||
| // 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. | ||
| // I ran the code the error i got was excatly as predicted. | ||
|
|
||
|
|
||
| // Consider: Why does it give this error? Is this what I predicted? If not, what's different? | ||
| // let prediction = " because of the lack of slice method available for numbers,I predict that the code will throw an error. | ||
| // the cardNumber variable is a number, and slice is a method that can only be used on strings or arrays."; | ||
| //slice is a method that can only be used on strings or arrays." // | ||
|
|
||
| // Then try updating the expression last4Digits is assigned to, in order to get the correct value | ||
|
|
||
| // The last4Digits variable should store the last 4 digits of cardNumber | ||
| console.log(last4Digits); // "4213" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,2 +1,5 @@ | ||
| const 12HourClockTime = "8:53pm"; | ||
| const 24hourClockTime = "20:53"; | ||
| const twelveHourClockTime = "8:53pm"; | ||
| // the code having an error because the variable is not named correctly,has to be twelvehourclocktime instead of 12hourclocktime. | ||
| const twentyFourHourClockTime = "20:53"; | ||
| // the code having an error because the variable is not named correctly,has to be twentyfourhourclocktime insted of 24hourclocktime. | ||
|
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,25 +1,32 @@ | ||
| const movieLength = 8784; // length of movie in seconds | ||
|
|
||
| const remainingSeconds = movieLength % 60; | ||
| const totalMinutes = (movieLength - remainingSeconds) / 60; | ||
|
|
||
| const remainingMinutes = totalMinutes % 60; | ||
| const totalHours = (totalMinutes - remainingMinutes) / 60; | ||
|
|
||
| const result = `${totalHours}:${remainingMinutes}:${remainingSeconds}`; | ||
| console.log(result); | ||
| const result = `${2,359}:${2,398}:${146,4}`; | ||
| console.log(movieLengthTime(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? | ||
| // 6 variables in total: movieLength, remainingSeconds, totalMinutes, remainingMinutes, totalHours, result | ||
|
|
||
| // b) How many function calls are there? | ||
| // there are 3 function calls in line 4,7 and 9 | ||
|
|
||
| // c) Using documentation, explain what the expression movieLength % 60 represents | ||
| // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Arithmetic_Operators | ||
|
|
||
| // d) Interpret line 4, what does the expression assigned to totalMinutes mean? | ||
|
|
||
| // it means that the movie hour is being calculated. totalminutes minus remainingseconds divided by 60. | ||
| // e) What do you think the variable result represents? Can you think of a better name for this variable? | ||
|
|
||
| // the variable result represents the total length it takes to watch the movie in hours and minutes. | ||
| //Better name is MovieLengthTime. | ||
| // f) Try experimenting with different values of movieLength. Will this code work for all values of movieLength? Explain your answer | ||
| // Yes, this code will work for different values of movieLength because it calculates the total hours, minutes and seconds based on the length of the movie in seconds. | ||
| // The code will correctly handle any length of movie in seconds and convert it to the appropriate format. | ||
|
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. It may run without any errors, but does it always end up in the correct format? Are there any edge cases? |
||
|
|
||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
I think there are a few more function calls to find