-
-
Notifications
You must be signed in to change notification settings - Fork 390
Birmingham | 26-ITP-May | Tobias Amaechina | Sprint 2 | coursework #1424
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
Tobias-Amaechina
wants to merge
49
commits into
CodeYourFuture:main
Choose a base branch
from
Tobias-Amaechina:acoursework/sprint-2
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
49 commits
Select commit
Hold shift + click to select a range
bd83096
predicted that there will be a syntaxError
Tobias-Amaechina c371756
called the function with arguement
Tobias-Amaechina cd270fb
interpreted the error message and suggested the fix
Tobias-Amaechina 31f5daf
commented out the original code so I can write the new code to fix …
Tobias-Amaechina 1d0572a
wrote a new code that fixed the syntaxErrot and console the called …
Tobias-Amaechina 782cf84
Predicted why an error will occur when the programm is run
Tobias-Amaechina 0292824
When the code was ran an error occured as preicted showing that the …
Tobias-Amaechina 99357d3
the error was fixed by reassignment instead of redeclaring the vari…
Tobias-Amaechina bb4f078
Explained what the error messages were saying and the line where they…
Tobias-Amaechina 2bca2a9
commented out the original program so I can write a new working code
Tobias-Amaechina 83f2a2a
removed the Variable reassignment to allow any decimal arguement to …
Tobias-Amaechina 5625879
commented out the original code
Tobias-Amaechina 5e1b919
wrote a new code that worked
Tobias-Amaechina 5cb01c7
gave my prediction of what the two console .log will print to the …
Tobias-Amaechina c6e3991
gave the explanation as to why the fist console.log inside the funct…
Tobias-Amaechina 637daa2
commented out the original code to allow re-writing a new one
Tobias-Amaechina 31c2ebd
wrote a new code that did not print undefined as a vaule
Tobias-Amaechina dee2a91
gave my prediction that the function when called will give undefined
Tobias-Amaechina 5d0b10b
gave an explanation as to why the console.log method produced undefined
Tobias-Amaechina 8e9bc16
added more context to the explantion -how semicolon ended the return…
Tobias-Amaechina 1e18211
commented out the original code to aid re-writing a new one
Tobias-Amaechina 3ced51b
wrote a new code that works
Tobias-Amaechina 92b372e
Wrote my prediction with an explanations
Tobias-Amaechina d6f096c
Wrote the ouput when the code was ran and compare them with my predi…
Tobias-Amaechina 14b44dc
Explained why the output 3 for the three different Arguements
Tobias-Amaechina b98f6b1
commented out the original code to allow for re-write of new code
Tobias-Amaechina 609ccf6
Wrote the new code to fix the scope issue with the global variable
Tobias-Amaechina 6c7e483
Explanation was given as to why the code did not work and how it wa…
Tobias-Amaechina 47a68fd
Added the return statment to the function's body
Tobias-Amaechina 4290aae
the function was called and console to the screen with the two argue…
Tobias-Amaechina 251d837
wrote the function with an apprioprate name
Tobias-Amaechina 760b0f9
used the programm in Sprint-1 and turn it into a resuable code by im…
Tobias-Amaechina 7ed11f3
Answered how many number of times the pad was called
Tobias-Amaechina 4f030b8
answere the question on the value assigned to pad when it's called f…
Tobias-Amaechina 356bd08
add comment sign to my earlier answer
Tobias-Amaechina 7fdc864
answere question on what is the return value of pad when called for …
Tobias-Amaechina cac50d0
Answered the question of assign value to num when pad was called t…
Tobias-Amaechina 65d9d7f
Answered question on the returned value to pad when its called the la…
Tobias-Amaechina 5ec6dee
reset the file to it's orinal state
Tobias-Amaechina cae676c
wrote an Assertion to test Mid-day , which failed
Tobias-Amaechina ee0dcaf
Wrote a code to fix the assertion
Tobias-Amaechina 0241153
wrote an assertion to test for Midnight , and it failed as it curren…
Tobias-Amaechina e3bb58b
wrote the code and corrected the variable namet 'targetOutput to ta…
Tobias-Amaechina 93705d4
removed the white space after the am in the current ouput for the mi…
Tobias-Amaechina 5ac78f9
adding comment to explain the assetion already witten to test when t…
Tobias-Amaechina d8396ef
fixed the code with String method and padStart method
Tobias-Amaechina 5e3b5f6
updated the code to only return number and not string
Tobias-Amaechina 65daf85
removed the template string to make the return value a number instea…
Tobias-Amaechina d58ef31
updated the template string with just number
Tobias-Amaechina 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,13 +1,22 @@ | ||
| // Predict and explain first... | ||
| // =============> write your prediction here | ||
| // =============> write your prediction here /* there will be a syntax error because the variable str is being declared twice in the same scope. The first declaration is in the function parameter, and the second declaration is inside the function body. This will cause a conflict and result in an error. */ | ||
|
|
||
| // call the function capitalise with a string input | ||
| // interpret the error message and figure out why an error is occurring | ||
|
|
||
| function capitalise(str) { | ||
| /*function capitalise(str) { | ||
| let str = `${str[0].toUpperCase()}${str.slice(1)}`; | ||
| return str; | ||
|
|
||
| } | ||
| capitalise("Tobias");*/ | ||
|
|
||
| // =============> write your explanation here | ||
| // =============> write your explanation here /* when the function `capitalise` is called with the argument "Tobias", it tries to declare a new variable `str` inside the function body using `let`. However, `str` is already declared as a parameter of the function. In JavaScript, you cannot declare a variable with the same name in the same scope, which leads to a syntax error and from the error message thus /home/tobi/CYF/Module-Structuring-and-Testing-Data/Sprint-2/1-key-errors/0.js:8 | ||
| /*let str = `${str[0].toUpperCase()}${str.slice(1)}`;SyntaxError: Identifier 'str' has already been declared it is pointing at line 8 as where the syntax error occurred so to fix the error the value on line 8 will need to be reassigned and not redeclared */ | ||
| // =============> write your new code here | ||
| function capitalise(str) { | ||
| str = `${str[0].toUpperCase()}${str.slice(1)}`; | ||
| return str; | ||
|
|
||
| } | ||
| console.log(capitalise("Tobias")); |
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,20 +1,38 @@ | ||
| // Predict and explain first... | ||
|
|
||
| // Why will an error occur when this program runs? | ||
| // =============> write your prediction here | ||
| // =============> write your prediction here. /* Error will occur when this program is run because a variable already declared inside the function parameter , was redeclared inside the function body. Also the console.log function is calling the variable decimalNumber which is not defined in the global scope. */ | ||
|
|
||
| // Try playing computer with the example to work out what is going on | ||
|
|
||
| function convertToPercentage(decimalNumber) { | ||
| const decimalNumber = 0.5; | ||
| /*function convertToPercentage(decimalNumber) { | ||
| decimalNumber = 0.5; | ||
| const percentage = `${decimalNumber * 100}%`; | ||
|
|
||
| return percentage; | ||
| } | ||
|
|
||
| console.log(decimalNumber); */ | ||
|
|
||
| // =============> write your explanation /* the first error SyntaxError pointed at line 9 as to where the error occurred and explained that the identifier-decimalNumber has already been declared. The second error ReferenceError pointed at line 15 as to where the error occurred and explained that the identifier-decimalNumber is not defined in the global scope. */ | ||
| /* /home/tobi/CYF/Module-Structuring-and-Testing-Data/Sprint-2/1-key-errors/1.js:9 | ||
| const decimalNumber = 0.5; | ||
| ^ | ||
|
|
||
| SyntaxError: Identifier 'decimalNumber' has already been declared*/ | ||
| /* /home/tobi/CYF/Module-Structuring-and-Testing-Data/Sprint-2/1-key-errors/1.js:15 | ||
| console.log(decimalNumber); | ||
| ^ | ||
|
|
||
| // =============> write your explanation here | ||
| ReferenceError: decimalNumber is not defined*/ | ||
|
|
||
| // Finally, correct the code to fix the problem | ||
| // =============> write your new code here | ||
| function convertToPercentage(decimalNumber) { | ||
| // removed the variable reassignment so that function call will work with any argument passed to it. | ||
| const percentage = `${decimalNumber * 100}%`; | ||
|
|
||
| return percentage; | ||
| } | ||
|
|
||
| console.log(convertToPercentage(0.75)); |
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,20 +1,24 @@ | ||
|
|
||
| // Predict and explain first BEFORE you run any code... | ||
| // Predict and explain first BEFORE you run any code...we are going to get a SyntaxError because the function parameter is a number and not a variable name. The function parameter should be a variable name that can be used inside the function body. | ||
|
|
||
| // this function should square any number but instead we're going to get an error | ||
|
|
||
| // =============> write your prediction of the error here | ||
| // =============> write your prediction of the error here // SyntaxError: Unexpected number. | ||
|
|
||
| function square(3) { | ||
| /*function square(3) { | ||
| return num * num; | ||
| } | ||
| }*/ | ||
|
|
||
| // =============> write the error message here | ||
| // =============> write the error message here /* /home/tobi/CYF/Module-Structuring-and-Testing-Data/Sprint-2/1-key-errors/2.js:8 function square(3) { SyntaxError: Unexpected number*/ | ||
|
|
||
| // =============> explain this error message here | ||
| // =============> explain this error message here/* this error is saying that something is wrong with the function parameter because it is a number and not a variable name. The function parameter should be a variable name that can be used inside the function body. the SyntaxError denote that the rule is violated, and pointed out that the number is unexpected at line 8 */ | ||
|
|
||
| // Finally, correct the code to fix the problem | ||
|
|
||
| // =============> write your new code here | ||
| function square(num) { | ||
| return num*num; | ||
| } | ||
| square(); | ||
|
|
||
|
|
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,14 +1,19 @@ | ||
| // Predict and explain first... | ||
|
|
||
| // =============> write your prediction here | ||
|
|
||
| function multiply(a, b) { | ||
| // =============> write your prediction here// The code will print 320 and undefine secondly. | ||
| /*function multiply(a, b) { | ||
| console.log(a * b); | ||
| } | ||
|
|
||
| console.log(`The result of multiplying 10 and 32 is ${multiply(10, 32)}`); | ||
| console.log(`The result of multiplying 10 and 32 is ${multiply(10, 32)}`);*/ | ||
|
|
||
| // =============> write your explanation here | ||
| // =============> write your explanation here. /* The function multiply is called inside the console.log statement, but it does not return any value. Instead, it only logs the result of multiplying a and b to the console. Therefore, when the console.log statement is executed, it will print "The result of multiplying 10 and 32 is undefined" because the multiply function does not return anything. The first console.log inside the multiply function will print 320 to the console, but the second console.log will print undefined. */ | ||
|
|
||
| // Finally, correct the code to fix the problem | ||
| // =============> write your new code here | ||
| function multiply(a, b) { | ||
| return a*b; | ||
|
|
||
| } | ||
|
|
||
| console.log(`The result of multiplying 10 and 32 is ${multiply(10, 32)}`); |
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,13 +1,18 @@ | ||
| // Predict and explain first... | ||
| // =============> write your prediction here | ||
|
|
||
| function sum(a, b) { | ||
| // =============> write your prediction here // will print undefined. | ||
| /*function sum(a, b) { | ||
| return; | ||
| a + b; | ||
| } | ||
|
|
||
| console.log(`The sum of 10 and 32 is ${sum(10, 32)}`); | ||
| console.log(`The sum of 10 and 32 is ${sum(10, 32)}`);*/ | ||
|
|
||
| // =============> write your explanation here.// The code will print undefined because the function sum does not return any value. Instead, it has a return statement with no value, because the semicolon ended the return statement which means it will return undefined by default. The second line of the function, a + b, is never executed because the return statement ends the function execution before it can be reached. | ||
|
|
||
| // =============> write your explanation here | ||
| // Finally, correct the code to fix the problem | ||
| // =============> write your new code here | ||
| function sum(a, b) { | ||
| return a + b; | ||
| } | ||
|
|
||
| console.log(`The sum of 10 and 32 is ${sum(10, 32)}`); |
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,24 +1,34 @@ | ||
| // Predict and explain first... | ||
|
|
||
| // Predict the output of the following code: | ||
| // =============> Write your prediction here | ||
| // =============> Write your prediction here./* The output will be 3 because the function getLastDigit is not using the argument passed to it, instead it is using the global variable num which is set to 103. Therefore, the last digit of 103 is 3 and that is what will be printed for all three console.log statements.*/ | ||
|
|
||
| const num = 103; | ||
| /*const num = 103; | ||
|
|
||
| function getLastDigit() { | ||
| return num.toString().slice(-1); | ||
| } | ||
|
|
||
| console.log(`The last digit of 42 is ${getLastDigit(42)}`); | ||
| console.log(`The last digit of 105 is ${getLastDigit(105)}`); | ||
| console.log(`The last digit of 806 is ${getLastDigit(806)}`); | ||
| console.log(`The last digit of 806 is ${getLastDigit(806)}`);*/ | ||
|
|
||
| // Now run the code and compare the output to your prediction | ||
| // =============> write the output here | ||
| // =============> write the output here// The out put is 3 for the three console.log calls as predicted | ||
| // Explain why the output is the way it is | ||
| // =============> write your explanation here | ||
| // =============> write your explanation here. /* The reason is because the function getLastDigit is not using the argument passed to it, instead it is using the global variable num which is set to 103. Therefore, the last digit of 103 is 3 and that is what will be printed for all three console.log statements.*/ | ||
| // Finally, correct the code to fix the problem | ||
| // =============> write your new code here | ||
|
|
||
|
|
||
|
|
||
| function getLastDigit(num) { | ||
| return num.toString().slice(-1); | ||
| } | ||
|
|
||
| console.log(`The last digit of 42 is ${getLastDigit(42)}`); | ||
| console.log(`The last digit of 105 is ${getLastDigit(105)}`); | ||
| console.log(`The last digit of 806 is ${getLastDigit(806)}`); | ||
|
|
||
| // This program should tell the user the last digit of each number. | ||
| // Explain why getLastDigit is not working properly - correct the problem | ||
| // Explain why getLastDigit is not working properly - correct the problem// The variable num was a global variable , that is is why it was not working becasue it was declared outside of the function and was fixed by declaring it inside the function as a parameter . |
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
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.
The calculation works here, but be careful about what the task is asking. The function should be returning the BMI to 1 decimal place. Your function is returning a string. How would you need to change this to match the task specification?
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.
Updated the return value now to number instead of string