-
Notifications
You must be signed in to change notification settings - Fork 2
Challenge Use Conditional Logic With If Else Statements
We can use if
statements in JavaScript to execute code only if the specified condition is met.
Each if
statement requires a boolean
condition to evaluate. If the boolean evaluates to true
, the statements inside the curly braces will execute. Otherwise, if it evaluates to false
, the code will not execute.
function trueOrFalse(myVal) {
if (myVal > 10) {
return "Greater Than";
}
return "Not Greater Than";
}
If myVal
is greater than 10
, the function will return "Greater Than"
. If it is not, the function will return "Not Greater Than"
. Both return
statements will never get executed because as soon as the first one is encountered, the execution exits the function and returns control to where the function was called.
Learn to code and help nonprofits. Join our open source community in 15 seconds at http://freecodecamp.com
Follow our Medium blog
Follow Quincy on Quora
Follow us on Twitter
Like us on Facebook
And be sure to click the "Star" button in the upper right of this page.
New to Free Code Camp?
JS Concepts
JS Language Reference
- arguments
- Array.prototype.filter
- Array.prototype.indexOf
- Array.prototype.map
- Array.prototype.pop
- Array.prototype.push
- Array.prototype.shift
- Array.prototype.slice
- Array.prototype.some
- Array.prototype.toString
- Boolean
- for loop
- for..in loop
- for..of loop
- String.prototype.split
- String.prototype.toLowerCase
- String.prototype.toUpperCase
- undefined
Other Links