2018-10-12 15:37:13 -04:00
---
title: Use conditional logic with If statements
---
2019-07-24 00:59:27 -07:00
# Use conditional logic with If statements
2018-10-12 15:37:13 -04:00
2019-07-24 00:59:27 -07:00
---
## Hints
### Hint 1
2018-10-12 15:37:13 -04:00
Your `if` statement will evaluate whether your `(condition)` is `true` or `false` and execute (if it evaluates to `true` ) the `{statement}` declared right after it.
2019-07-24 00:59:27 -07:00
### Hint 2
2018-10-12 15:37:13 -04:00
In case your `(condition)` evaluates to `false` the `{statement}` won't be executed and function will return the next `return` statement.
2019-07-24 00:59:27 -07:00
---
## Solutions
2018-10-12 15:37:13 -04:00
2019-07-24 00:59:27 -07:00
< details > < summary > Solution 1 (Click to Show/Hide)< / summary >
2018-10-12 15:37:13 -04:00
```javascript
// Setup
function trueOrFalse(wasThatTrue) {
// Only change code below this line.
2019-07-24 00:59:27 -07:00
if (wasThatTrue) {
2018-10-12 15:37:13 -04:00
return "Yes, that was true";
2019-07-24 00:59:27 -07:00
}
2018-10-12 15:37:13 -04:00
return "No, that was false";
2019-07-24 00:59:27 -07:00
// Only change code above this line.
}
2018-10-12 15:37:13 -04:00
```
2019-07-24 00:59:27 -07:00
#### Code Explanation
2018-10-12 15:37:13 -04:00
The function first evaluates `if` the condition `(wasThatTrue)` evaluates to `true` . If it does, ir returns the statement between the curly braces. If it doesn't, it returns the next `return` statement outside them.
2019-07-24 00:59:27 -07:00
#### Relevant Links
2018-10-12 15:37:13 -04:00
- ["Boolean" - MDN Glossary ](https://developer.mozilla.org/en-US/docs/Glossary/Boolean )
- ["if...else" - MDN JavaScript reference ](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/if...else )
2019-07-24 00:59:27 -07:00
< / details >