Skip to content

Commit

Permalink
update readme to have brief functions intro
Browse files Browse the repository at this point in the history
  • Loading branch information
maxwell committed Apr 9, 2018
1 parent a17496a commit 6b5d151
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
1 change: 1 addition & 0 deletions .learn
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ tags:
- if
- else
- lab
- functions
languages:
- javascript
resources:
Expand Down
13 changes: 9 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,14 +49,17 @@ If we run the tests with the `learn` command, we see that
`scuberGreetingForFeet` in the `index.js` file.

...but wait! We haven't gone over writing functions yet! We will tackle the
details of function writing in an upcoming lab. For now, briefly, a function
declaration is written like so:
details of function writing in depth in an upcoming lab. For now, briefly, a
function declaration is written like so:

```js
function addFive(someNumber) {
//everything I want my function to do I put inside these curly braces
//in this example, I want my function, addFive, to add 5 to any number I pass in (someNumber)
let result = someNumber + 5;
//in this example, lets say I want my function, addFive, to add 5 to any number I pass in (someNumber), but only IF the number is greater than zero
let result
if (someNumber > 0) {
result = someNumber + 5;
}
//at the end, if I want my function to return something, I need to state it:
return result
}
Expand All @@ -68,6 +71,8 @@ addFive(10);
//returns 15
addFive(20);
//returns 25
addFive(-5);
//returns undefined
addFive(addFive(5));
//returns 15!! In this case, the return value of addFive(5), 10, is passed in as the argument to the outer addFive, returning 15
```
Expand Down

0 comments on commit 6b5d151

Please sign in to comment.