-
-
Notifications
You must be signed in to change notification settings - Fork 546
Manchester | 26-ITP-Sept | Aklilu Tsehaye | Sprint 3 | Coursework/sprint 3 #1632
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
AkliluMihtsun
wants to merge
16
commits into
CodeYourFuture:main
Choose a base branch
from
AkliluMihtsun:coursework/sprint-3
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
16 commits
Select commit
Hold shift + click to select a range
4c29df2
Fix HTML doctype casing and add CSS styles for form layout
AkliluMihtsun 2a3a27d
Fix variable redeclaration error in capitalise function
AkliluMihtsun 4eaa3d3
Fix variable redeclaration and update function call in percentage con…
AkliluMihtsun 47e6f25
Fix function parameter declaration and update error prediction comments
AkliluMihtsun 1250064
Explaning and fixing the bug by adding return keyword
AkliluMihtsun 0e0827d
Explained and fixed the bug proper use of return statment
AkliluMihtsun 8ad0bd9
Explaining and fixing the bug by adding parameter
AkliluMihtsun 92ecd91
created a function that calculates BMI and returns string with one de…
AkliluMihtsun 0fee258
creating a function that uppercases string and replace empty space
AkliluMihtsun 6e72bf1
implementing the function that changes different input in to pounds
AkliluMihtsun 481cdd2
added explanation about the function call
AkliluMihtsun 0d560fc
refactor formatAs12HourClock function to handle input validation and …
AkliluMihtsun 0f24ef2
Complete Sprint-3 coursework
AkliluMihtsun a630a94
removing the html and css files from coursework/sprint-3 branch
AkliluMihtsun 32f4dc8
added suggested comments
AkliluMihtsun 29aa0a1
added more cases and explanations
AkliluMihtsun 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 | ||
|
|
||
| // 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; | ||
| } | ||
|
|
||
| // =============> write your explanation here | ||
| // =============> write your new code here | ||
| // Predict and explain first... | ||
| // I am predicting the code will generate error because the variable str is declared twice | ||
|
|
||
| // 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; | ||
| } | ||
| console.log(capitalise("hello World"));*/ | ||
|
|
||
| // After we run the code, it generated this error SyntaxError: Identifier str has already been declared | ||
| // This happened because we tried to declare again using the keyword let the variable str | ||
| // which was declared before in the parameter of the function | ||
|
|
||
| //Here is the fixed code | ||
| function capitalise(str) { | ||
| str = `${str[0].toUpperCase()}${str.slice(1)}`; | ||
| return str; | ||
| } | ||
| console.log(capitalise("hello World")); |
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,32 @@ | ||
| // Predict and explain first... | ||
|
|
||
| // Why will an error occur when this program runs? | ||
| // =============> write your prediction here | ||
|
|
||
| // Try playing computer with the example to work out what is going on | ||
|
|
||
| function convertToPercentage(decimalNumber) { | ||
| const decimalNumber = 0.5; | ||
| const percentage = `${decimalNumber * 100}%`; | ||
|
|
||
| return percentage; | ||
| } | ||
|
|
||
| console.log(decimalNumber); | ||
|
|
||
| // =============> write your explanation here | ||
|
|
||
| // Finally, correct the code to fix the problem | ||
| // =============> write your new code here | ||
| // Predict and explain first... | ||
|
|
||
| // Why will an error occur when this program runs? | ||
| // I predict the code will generate 2 errors because one the variable decimalNumber is declared twice and two | ||
| // the function is not called instead the variable decimalNumber is called and it can't be accessed because | ||
| // it was declared locally as a parameter of the function | ||
|
|
||
| // Try playing computer with the example to work out what is going on | ||
|
|
||
| /*function convertToPercentage(decimalNumber) { | ||
| const decimalNumber = 0.5; | ||
| const percentage = `${decimalNumber * 100}%`; | ||
|
|
||
| return percentage; | ||
| } | ||
|
|
||
| console.log(decimalNumber);*/ | ||
|
|
||
| // After we run the code, it generated an error SyntaxError: Identifier 'decimalNumber' has already been declared | ||
| // because we tried to declare decimalNumber again. After fixing this error again we got another error ReferenceError: decimalNumber is not defined | ||
| // because the decimalNumber is locally scoped, javascript can't access it when the function is called | ||
| // additionally the function was not called console.log(decimalNumber) this simply means print the value of decimalNumber | ||
|
|
||
| // Finally, correct the code to fix the problem | ||
| // Here is the fixed code | ||
| function convertToPercentage(decimalNumber) { | ||
| const percentage = `${decimalNumber * 100}%`; | ||
|
|
||
| return percentage; | ||
| } | ||
|
|
||
| console.log(convertToPercentage(0.5)); |
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,21 @@ | ||
|
|
||
| // Predict and explain first BEFORE you run any code... | ||
|
|
||
| // this function should square any number but instead we're going to get an error | ||
|
|
||
| // =============> write your prediction of the error here | ||
|
|
||
| function square(3) { | ||
| return num * num; | ||
| } | ||
|
|
||
| // =============> write the error message here | ||
|
|
||
| // =============> explain this error message here | ||
|
|
||
| // Finally, correct the code to fix the problem | ||
|
|
||
| // =============> write your new code here | ||
|
|
||
|
|
||
| // Predict and explain first BEFORE you run any code... | ||
|
|
||
| // this function should square any number but instead we're going to get an error | ||
|
|
||
| // I predict the error will come from the argument because when we write a function we first declare parameters not values | ||
|
|
||
| /*function square(3) { | ||
| return num * num; | ||
| }*/ | ||
|
|
||
| // SyntaxError: Unexpected number | ||
|
|
||
| // this error tells us javascript expects valid variable identifiers when function is defined not values | ||
|
|
||
| // Finally, correct the code to fix the problem | ||
|
|
||
| // Here is the fixed code | ||
| function square(num) { | ||
| return num * num; | ||
| } | ||
| console.log(square(3)); |
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,22 @@ | ||
| // Predict and explain first... | ||
|
|
||
| // =============> write your prediction here | ||
|
|
||
| function multiply(a, b) { | ||
| console.log(a * b); | ||
| } | ||
|
|
||
| console.log(`The result of multiplying 10 and 32 is ${multiply(10, 32)}`); | ||
|
|
||
| // =============> write your explanation here | ||
|
|
||
| // Finally, correct the code to fix the problem | ||
| // =============> write your new code here | ||
| // Predict and explain first... | ||
|
|
||
| // I predict the code will run normally and print the result of a * b on the first console, but it will return undefined on the | ||
| // second console.log | ||
|
|
||
| /*function multiply(a, b) { | ||
| console.log(a * b); | ||
| } | ||
|
|
||
| console.log(`The result of multiplying 10 and 32 is ${multiply(10, 32)}`);*/ | ||
|
|
||
| // The reason for printing undefined is that we didn't define a return value so the js doesn't know what to return and it simply returns undefined | ||
| // We can fix the code by replacing the console.log with a return keyword so the js knows what to return when the function is called | ||
|
|
||
| // Finally, correct the code to fix the problem | ||
| // Here is the fixed code | ||
|
|
||
| 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,21 @@ | ||
| // Predict and explain first... | ||
| // =============> write your prediction here | ||
|
|
||
| function sum(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 | ||
| // Predict and explain first... | ||
| // I predict that the code will run but it will print undefined because the return expression is not setup properly | ||
|
|
||
| /*function sum(a, b) { | ||
| return; | ||
| a + b; | ||
| } | ||
|
|
||
| console.log(`The sum of 10 and 32 is ${sum(10, 32)}`);*/ | ||
|
|
||
| // When we run the code it printed out undefined because the return keyword is there but the expression that needs to be returned is not on the same line | ||
| // therefore the return keyword can't reach the expression and the expression is ignored because the function has done execution right after it reaches the return keyword | ||
|
|
||
| // Finally, correct the code to fix the problem | ||
| // Here is the fixed code | ||
|
|
||
| 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,36 @@ | ||
| // Predict and explain first... | ||
|
|
||
| // Predict the output of the following code: | ||
| // =============> Write your prediction here | ||
|
|
||
| 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)}`); | ||
|
|
||
| // Now run the code and compare the output to your prediction | ||
| // =============> write the output here | ||
| // Explain why the output is the way it is | ||
| // =============> write your explanation here | ||
| // Finally, correct the code to fix the problem | ||
| // =============> write your new code here | ||
|
|
||
| // This program should tell the user the last digit of each number. | ||
| // Explain why getLastDigit is not working properly - correct the problem | ||
| // Predict and explain first... | ||
|
|
||
| // Predict the output of the following code: | ||
| // I predict the code will run but will give us unexpected output as the function does not have parameter but we provided an argument | ||
|
|
||
| /*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)}`);*/ | ||
|
|
||
| // Now run the code and compare the output to your prediction | ||
| // The last digit of 42 is 3 | ||
| // The last digit of 105 is 3 | ||
| // The last digit of 806 is 3 | ||
|
|
||
| // Explain why the output is the way it is | ||
| // It is because we declared a function with no parameters so the function will ignore any arguments we provide | ||
| // since the var num is declared and assigned with a value so every time the function is called it will use the var num | ||
|
|
||
| // Finally, correct the code to fix the problem | ||
| // Here is the fixed code | ||
| 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 |
|---|---|---|
| @@ -1,19 +1,23 @@ | ||
| // Below are the steps for how BMI is calculated | ||
|
|
||
| // The BMI calculation divides an adult's weight in kilograms (kg) by their height in metres (m) squared. | ||
|
|
||
| // For example, if you weigh 70kg (around 11 stone) and are 1.73m (around 5 feet 8 inches) tall, you work out your BMI by: | ||
|
|
||
| // squaring your height: 1.73 x 1.73 = 2.99 | ||
| // dividing 70 by 2.99 = 23.41 | ||
| // Your result will be displayed to 1 decimal place, for example '23.4'. | ||
|
|
||
| // You will need to implement a function that calculates the BMI of someone based off their weight and height | ||
|
|
||
| // Given someone's weight in kg and height in metres | ||
| // Then when we call this function with the weight and height | ||
| // It should return a string of their Body Mass Index to 1 decimal place | ||
|
|
||
| function calculateBMI(weight, height) { | ||
| // return the BMI of someone based off their weight and height | ||
| } | ||
| // Below are the steps for how BMI is calculated | ||
|
|
||
| // The BMI calculation divides an adult's weight in kilograms (kg) by their height in metres (m) squared. | ||
|
|
||
| // For example, if you weigh 70kg (around 11 stone) and are 1.73m (around 5 feet 8 inches) tall, you work out your BMI by: | ||
|
|
||
| // squaring your height: 1.73 x 1.73 = 2.99 | ||
| // dividing 70 by 2.99 = 23.41 | ||
| // Your result will be displayed to 1 decimal place, for example '23.4'. | ||
|
|
||
| // You will need to implement a function that calculates the BMI of someone based off their weight and height | ||
|
|
||
| // Given someone's weight in kg and height in metres | ||
| // Then when we call this function with the weight and height | ||
| // It should return a string of their Body Mass Index to 1 decimal place | ||
|
|
||
| function calculateBMI(weight, height) { | ||
| const BMI = weight / height ** 2; | ||
| const stringBMI = BMI.toString(); | ||
| return stringBMI.slice(0, stringBMI.indexOf(".") + 2); | ||
| } | ||
|
|
||
| console.log(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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,16 +1,20 @@ | ||
| // A set of words can be grouped together in different cases. | ||
|
|
||
| // For example, "hello there" in snake case would be written "hello_there" | ||
| // UPPER_SNAKE_CASE means taking a string and writing it in all caps with underscores instead of spaces. | ||
|
|
||
| // Implement a function that: | ||
|
|
||
| // Given a string input like "hello there" | ||
| // When we call this function with the input string | ||
| // it returns the string in UPPER_SNAKE_CASE, so "HELLO_THERE" | ||
|
|
||
| // Another example: "lord of the rings" should be "LORD_OF_THE_RINGS" | ||
|
|
||
| // You will need to come up with an appropriate name for the function | ||
| // Use the MDN string documentation to help you find a solution | ||
| // This might help https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/toUpperCase | ||
| // A set of words can be grouped together in different cases. | ||
|
|
||
| // For example, "hello there" in snake case would be written "hello_there" | ||
| // UPPER_SNAKE_CASE means taking a string and writing it in all caps with underscores instead of spaces. | ||
|
|
||
| // Implement a function that: | ||
|
|
||
| // Given a string input like "hello there" | ||
| // When we call this function with the input string | ||
| // it returns the string in UPPER_SNAKE_CASE, so "HELLO_THERE" | ||
|
|
||
| // Another example: "lord of the rings" should be "LORD_OF_THE_RINGS" | ||
|
|
||
| // You will need to come up with an appropriate name for the function | ||
| // Use the MDN string documentation to help you find a solution | ||
| // This might help https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/toUpperCase | ||
| function uppercaseAndUnderscore(word) { | ||
| return word.toUpperCase().replaceAll(" ", "_"); | ||
| } | ||
| console.log(uppercaseAndUnderscore("welcome to cyf")); |
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,6 +1,25 @@ | ||
| // In Sprint-1, there is a program written in 3-mandatory-interpret/3-to-pounds.js | ||
|
|
||
| // You will need to take this code and turn it into a reusable block of code. | ||
| // You will need to declare a function called toPounds with an appropriately named parameter. | ||
|
|
||
| // You should call this function a number of times to check it works for different inputs | ||
| // In Sprint-1, there is a program written in 3-mandatory-interpret/3-to-pounds.js | ||
|
|
||
| // You will need to take this code and turn it into a reusable block of code. | ||
| // You will need to declare a function called toPounds with an appropriately named parameter. | ||
|
|
||
| // You should call this function a number of times to check it works for different inputs | ||
|
|
||
| function toPounds(penceString) { | ||
| if (penceString == "") { | ||
| return "please put the amount"; | ||
| } | ||
| const totalPence = parseInt(penceString, 10); | ||
| const pounds = totalPence / 100; | ||
| const formattedPound = pounds.toFixed(2); | ||
| return "£" + formattedPound; | ||
| } | ||
|
|
||
| console.log(toPounds("1991p")); | ||
| console.log(toPounds("2020p")); | ||
| console.log(toPounds("399p")); | ||
| console.log(toPounds("69p")); | ||
| console.log(toPounds("00p ")); | ||
| console.log(toPounds(" 50p ")); | ||
| console.log(toPounds("232423")); | ||
| console.log(toPounds("")); |
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.