generated from CodeYourFuture/Module-Template
-
-
Notifications
You must be signed in to change notification settings - Fork 198
CYF London | Rihanna Poursoltani | Module Structuring and Testing Data | Sprint 2 #233
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
Closed
Closed
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
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,7 +1,12 @@ | ||
// Predict and explain first... | ||
//* When we execute this code, it calls the multiply function , we will have the log of the function by console.log inside of the | ||
// function >(320). However because the function doesn't have return statement so the value in the template literal will be undefined. | ||
|
||
|
||
//* To fix this we can put return statement and return the value to the template literal. | ||
|
||
function multiply(a, b) { | ||
console.log(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,8 +1,11 @@ | ||
// Predict and explain first... | ||
//* When this code run we will call the sum function with two parameters (a and b) by the template literal, inside of the function | ||
// when return statement execute code will exit the function and any statement after return won't execute (line a + b) so it will ignore | ||
// so value in the template literal would be undefined. | ||
|
||
//* To fix this we need to pass the sum in the return statement | ||
function sum(a, b) { | ||
return; | ||
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
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 @@ | ||
// Predict and explain first... | ||
|
||
//*The capitalise function takes a string as input (str parameter here) and then will make the first letter of the string, capital but this | ||
// *code has an error because it declared str inside of the function. | ||
|
||
// call the function capitalise with a string input | ||
// interpret the error message and figure out why an error is occurring | ||
|
||
//*"SyntaxError: Identifier 'str' has already been declared" | ||
//* The reason that we have this error is we declared "str" as a parameter for the function and then inside the function we tried to | ||
//* declare it again that is wrong! For fixing this problem we can remove let and then reassign the value. | ||
|
||
function capitalise(str) { | ||
let str = `${str[0].toUpperCase()}${str.slice(1)}`; | ||
str = `${str[0].toUpperCase()}${str.slice(1)}`; | ||
return str; | ||
} | ||
let test = capitalise("hello") | ||
console.log(test) // OUTPUT ; "Hello" | ||
|
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... | ||
//* This code will have errors like Syntax errors, reference error ... | ||
|
||
// Why will an error occur when this program runs? | ||
// Try playing computer with the example to work out what is going on | ||
//* 1. "SyntaxError: Identifier 'decimalNumber' has already been declared" > decimalNumber is declared as a parameter for the function | ||
// but it declared again inside of the function that it cause syntax error. | ||
//* 2. "ReferenceError: decimalNumber is not defined" > decimalNumber value is defined inside of the function so it is in a local scop | ||
// then there is no access to it outside of the function so we will see reference error. | ||
|
||
// Try playing computer with the example to work out what is going on | ||
//* For fixing this problem we need to remove second declaration of decimalNumber and use it as a parameter directly. | ||
//* Then we need to call the function in console.log to see the result. So we can put the value of 0.5 as a parameter in the function | ||
// and call it | ||
function convertToPercentage(decimalNumber) { | ||
const decimalNumber = 0.5; | ||
const percentage = `${decimalNumber * 100}%`; | ||
|
||
return percentage; | ||
} | ||
|
||
console.log(decimalNumber); | ||
console.log(convertToPercentage(0.5)); // OUTPUT ; "50%" |
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,10 +1,14 @@ | ||
|
||
// Predict and explain first... | ||
//* When we execute the code we will have Syntax error because of the number 3 in the function. We can not define a parameter value | ||
// in the function, we are allowed to pass parameter name. Also num inside of the function is not defined and will show reference error | ||
|
||
// this function should square any number but instead we're going to get an error | ||
//* To fix this code we need to remove number 3 and pass the parameter name "num". Also we need to call function, we can print it with | ||
// console.log | ||
|
||
function square(3) { | ||
function square(num) { | ||
return num * num; | ||
} | ||
|
||
|
||
console.log(square(3)); // OUTPUT ; 9 |
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
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.
Uh oh!
There was an error while loading. Please reload this page.