Skip to content

Commit

Permalink
Add concepts
Browse files Browse the repository at this point in the history
  • Loading branch information
iHiD committed Jan 20, 2025
1 parent d0199b3 commit 92461af
Show file tree
Hide file tree
Showing 4 changed files with 76 additions and 2 deletions.
16 changes: 16 additions & 0 deletions bootcamp_content/concepts/conditionals.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,3 +40,19 @@ We can use a function where he gets someone's age based on their name.
And then he compares it to the entry critera for the club:

<img src="https://assets.exercism.org/bootcamp/diagrams/if-bouncer-functions.png" class="diagram"/>

## Joining conditions

Finally, sometimes we might want to say "if something and something else". To achieve this we can use the `and` keyword.

Imagine a nightclub that's disco themed. Only people 21 or over dressed in Disco clothes can get it. For this we can use an `and` statement to combine the two conditions:

<img src="https://assets.exercism.org/bootcamp/diagrams/conditions-and.png" class="diagram"/>

It's important to remember that both sides of the `and` are individual conditions. Both most be comparisons that equate to `true` or `false`:

<img src="https://assets.exercism.org/bootcamp/diagrams/conditions-and-valid.png" class="diagram"/>

---

### Next Concept: [Else Statements](./else-statements.md)
18 changes: 16 additions & 2 deletions bootcamp_content/concepts/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -76,12 +76,26 @@
"description": "Learn how to pass inputs (also know as 'arguments') into functions.",
"level": 1
},
{
"slug": "functions-return",
"parent": "functions",
"title": "Function that return things",
"description": "Learn about functions that return things and how to use them.",
"level": 3
},
{
"slug": "conditionals",
"parent": "flow-control",
"title": "Conditionals",
"description": "Learn about if and else statements.",
"level": 4
"description": "Learn about if statements.",
"level": 3
},
{
"slug": "else-statements",
"parent": "flow-control",
"title": "Else Statements",
"description": "Learn about else statements.",
"level": 3
},
{
"slug": "loops-repeat",
Expand Down
21 changes: 21 additions & 0 deletions bootcamp_content/concepts/else-statements.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Else Statements

It's great to be able to use an `if` statement to do something if a condition is `true`.
But what about when a condition is false?

That's where `else` (and `else if` statements come in!)

Else statements allow us to provide a block of code for Jiki to run when the `if` statement's condition is false.

<img src="https://assets.exercism.org/bootcamp/diagrams/else-statement-anatomy.png" class="diagram"/>

So going back to Jiki functioning as a Robot-bouncer at a club, he could a `reject()` function to send someone away if they're not the right age (rather than just staring silently at them like he did before!)

<img src="https://assets.exercism.org/bootcamp/diagrams/else-example.png" class="diagram"/>

### Else if

We can chain statements together using `else if`.
And we can still have a final `else` on that too.

<img src="https://assets.exercism.org/bootcamp/diagrams/else-if-statement-anatomy.png" class="diagram"/>
23 changes: 23 additions & 0 deletions bootcamp_content/concepts/functions-return.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Functions that return

As well as doing things, functions often return things back to Jiki.

This isn't like printing to a screen, or outputting something.
This is very specifically the function returning something to **Jiki** to use later.

Image we have a `current_time` function that gives us the current time back out as a string. When Jiki uses it, he gets a string with the time on that he can then use:

<img src="https://assets.exercism.org/bootcamp/diagrams/function-return-current-time.png" class="diagram"/>

He could do various things with this, such as store it in a variable:

<img src="https://assets.exercism.org/bootcamp/diagrams/function-return-store-current-time.png" class="diagram"/>

This works exactly the same with functions that have inputs.
Imagine a `join` function that takes two strings and joins them with a space in between:

<img src="https://assets.exercism.org/bootcamp/diagrams/function-return-join.png" class="diagram"/>

Just like before, we could ask Jiki to store the result in a variable:

<img src="https://assets.exercism.org/bootcamp/diagrams/function-return-store-join.png" class="diagram"/>

0 comments on commit 92461af

Please sign in to comment.