Last active
February 16, 2016 20:20
-
-
Save gringogidget/e43b24d6de3608021474 to your computer and use it in GitHub Desktop.
JS Notes
This file contains 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
> Greater than | |
>= Greater than or equal to | |
< Less than | |
<= Less than or equal to | |
== Equal to (equality operator eg "3" == 3 is true) | |
=== Strict equal to (strict equality operator type as well as value eg "3" == 3 is false) | |
!= Not equal to | |
!== Strict not equal to |
This file contains 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
// Conditional Statements // (Bascially, "IF this is true THEN do that") | |
var answer = prompt('What programming language is the name of a gem?'); | |
if () { | |
} | |
- Conditional statements begin with the "if" keyword. | |
- After the keyword, come a pair of parentheses (). | |
- Inside the parentheses goes the condition. | |
A condition is a simple trick whose answer is either true or false. | |
- After the condition are a set of curly braces {}. | |
This is for the set of code to run IF the condition is TRUE. | |
The braces form what's called a "code block" which can hold one or more JS statements. | |
There is no semicolon after the last curly brace. | |
- An equality operator (===) checks to see if two values are the same. | |
eg: | |
if (answer === 'Ruby') { | |
document.write("<p>That's right!</p>"); | |
} | |
This file contains 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
// Else Clause (What to do if the IF is false) | |
var answer = prompt('What programming language is the name of a gem?'); | |
if (answer === 'Ruby') { | |
document.write("<p>That's right!</p>"); | |
} else { | |
document.write("<p>Sorry, that's wrong.</p>"); | |
} | |
*****Bonus:***** | |
Since the answer is case sensitive, change: | |
if (answer === 'Ruby') { | |
to | |
if (answer.toUpperCase() === 'RUBY') { |
This file contains 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
ok |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
// Build a Random Number Guessing Game