generated from CodeYourFuture/Module-Template
-
-
Notifications
You must be signed in to change notification settings - Fork 240
Glasgow | 25-ITP-Sep | Christelle Boten | Sprint 2 | Coursework Sprint 2 #852
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
Christelle-b
wants to merge
11
commits into
CodeYourFuture:main
Choose a base branch
from
Christelle-b:coursework/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
11 commits
Select commit
Hold shift + click to select a range
16a9631
change 1.0
Christelle-b 31d028d
1.1
Christelle-b 0771dcc
1.2
Christelle-b 45967b9
2.0
Christelle-b d473199
2.1
Christelle-b fb0d426
2.2
Christelle-b e5ddf14
3.2
Christelle-b 20299c0
3.3
Christelle-b fca7143
4- time format
Christelle-b b4e309a
5 - format time
Christelle-b ba98d73
bmi updates
Christelle-b 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
Some comments aren't visible on the classic Files Changed page.
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,20 @@ | ||
| // Predict and explain first... | ||
| // =============> write your prediction here | ||
| // I believe the code is trying to write the first letter of a string on capital letter. But since the "str" declaration has already been used, we will need a new name | ||
|
|
||
| // call the function capitalise with a string input | ||
| // interpret the error message and figure out why an error is occurring | ||
|
|
||
| function capitalise(str) { | ||
| let str = `${str[0].toUpperCase()}${str.slice(1)}`; | ||
| return str; | ||
| } | ||
| // function capitalise(str) { | ||
| // let str = `${str[0].toUpperCase()}${str.slice(1)}`; | ||
| // return str; | ||
| // } | ||
|
|
||
| // =============> write your explanation here | ||
| // =============> write your explanation here: //There is a SynthaxError on line 9 of the code when we try to declare a new variable with the name "str". This is because the "str" name has already been used when declaring the function "capitalise". | ||
| // =============> write your new code here | ||
| function capitalise(str) { | ||
| let name = `${str[0].toUpperCase()}${str.slice(1)}`; | ||
| return name; | ||
| } | ||
| let str = "emma"; | ||
| console.log(capitalise(str)); |
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,30 @@ | ||
| // Predict and explain first... | ||
|
|
||
| // Why will an error occur when this program runs? | ||
| // =============> write your prediction here | ||
| // Here the name decimalNumber in 'const decimalNumber' has already been used, so we will get a synthax Error for that line. | ||
|
|
||
| // Try playing computer with the example to work out what is going on | ||
|
|
||
| function convertToPercentage(decimalNumber) { | ||
| const decimalNumber = 0.5; | ||
| const percentage = `${decimalNumber * 100}%`; | ||
| // function convertToPercentage(decimalNumber) { | ||
| // const decimalNumber = 0.5; | ||
| // const percentage = `${decimalNumber * 100}%`; | ||
|
|
||
| return percentage; | ||
| } | ||
| // return percentage; | ||
| // } | ||
|
|
||
| console.log(decimalNumber); | ||
|
|
||
| // =============> write your explanation here | ||
| // console.log(decimalNumber); | ||
|
|
||
| // JavaScript is read from top to bottom, so when the processor reads an error, the program will stop running and will get the error message. | ||
| //The first error is on line 9 with the reuse of the variable declaration name of 'decimalNumber. | ||
| //The second error is on line 15 where we are trying to call the variable 'decimalNumber',which is a local variable inside the function. We cannot access this variable outside of the function. We will need to call the whole function. | ||
| // Finally, correct the code to fix the problem | ||
| // =============> write your new code here | ||
| function convertToPercentage(decimalNumber) { | ||
| const percentage = `${(decimalNumber * 100).toFixed(2)}`; | ||
| return percentage; | ||
| } | ||
|
|
||
|
|
||
| console.log(convertToPercentage(0.5)); | ||
| console.log(convertToPercentage(0.1234)); | ||
| console.log(convertToPercentage(1)); | ||
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,14 +1,19 @@ | ||
| // Predict and explain first... | ||
|
|
||
| // =============> write your prediction here | ||
| // =============> write your prediction here: There is no return value value for the function multiply. Though it print the value of a * b in the function, this function cannot be called outside of the function (on line 9). So, it will be undefinded. WE need a return | ||
|
|
||
| function multiply(a, b) { | ||
| console.log(a * b); | ||
| } | ||
| // 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: We need to change console.log on line 6 to return so that we can call in outside of the function. | ||
|
|
||
| // 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,19 @@ | ||
| // Predict and explain first... | ||
| // =============> write your prediction here | ||
| // =============> write your prediction here: There is a semi column on line 5 after the return which separates it from line 6. We don't know what we are returning. | ||
|
|
||
| // function sum(a, b) { | ||
| // return; | ||
| // a + b; | ||
| // } | ||
|
|
||
| // console.log(`The sum of 10 and 32 is ${sum(10, 32)}`); | ||
|
|
||
| // =============> write your explanation here: SInce we don't know what we are returning, we will get an undefined value for the function. | ||
| // Finally, correct the code to fix the problem | ||
| // =============> write your new code here | ||
| function sum(a, b) { | ||
| return; | ||
| a + b; | ||
| return a + b; | ||
| } | ||
|
|
||
| console.log(`The sum of 10 and 32 is ${sum(10, 32)}`); | ||
|
|
||
| // =============> write your explanation here | ||
| // Finally, correct the code to fix the problem | ||
| // =============> write your new code here |
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,33 @@ | ||
| // Predict and explain first... | ||
|
|
||
| // Predict the output of the following code: | ||
| // =============> Write your prediction here | ||
| // =============> Write your prediction here: We are trying to convert the last figure (last index) of a number to a String. We will surely get "2", "5" and "6" | ||
|
|
||
| const num = 103; | ||
| // const num = 103; | ||
|
|
||
| function getLastDigit() { | ||
| return num.toString().slice(-1); | ||
| } | ||
| // 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 42 is ${getLastDigit(42)}`); | ||
| // console.log(`The last digit of 105 is ${getLastDigit(105)}`); | ||
| // 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: After running our code, we saw that it printed "3" all over. Which comes from our initial declaration of num = 103 | ||
| // Explain why the output is the way it is | ||
| // =============> write your explanation here | ||
| // =============> write your explanation here: We have declared num as a const which makes it unchangeable through out. We cannot redeclare it. The second thing is that we will need to add num inside of the parameter of the function. | ||
| // Finally, correct the code to fix the problem | ||
| // =============> write your new code here | ||
| let num = 103; | ||
|
|
||
| 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 |
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 |
|---|---|---|
|
|
@@ -14,6 +14,11 @@ | |
| // Then when we call this function with the weight and height | ||
| // It should return their Body Mass Index to 1 decimal place | ||
|
|
||
| function calculateBMI(weight, height) { | ||
| // return the BMI of someone based off their weight and height | ||
| } | ||
| function calculateBmi(weight, height) { | ||
| const squareHeight = height * height; | ||
| const divide = weight / squareHeight; | ||
|
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. I think |
||
| // let BMI = divide.toFixed(2); | ||
| return Number(divide.toFixed(1)); | ||
| } | ||
| console.log(calculateBmi(70, 1.73)); | ||
| console.log(typeof calculateBmi(70, 1.73)); | ||
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
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.
Missing a
%.