if (condition is true) { // then do this .... }
if(2 + 2 == 4) { console.log("You are a mathmatician!"); }
if(prompt("Your name?") != "Estelle"){ console.log("You are an imposter!"); }
Press → key to advance. Zoom in/out: Ctrl or Command + +/-.
if (condition is true) { // then do this .... }
if(2 + 2 == 4) { console.log("You are a mathmatician!"); }
if(prompt("Your name?") != "Estelle"){ console.log("You are an imposter!"); }
Operator | Definition |
---|---|
== | Equal to |
=== | Equal to & same type |
!= | Not Equal to |
> | Greater than |
>= | Greater or equal to |
< | Less than |
<= | Less or equal to |
! | Not |
&& | AND |
|| | OR |
var firstName = prompt('First Name?'); if(firstName.toUpperCase() === 'ESTELLE') { alert(firstName); }
var errMsg, email1 = prompt('Your email address:'); email2 = prompt('Re-enter email address:'); if (email1.toUpperCase() != email2.toUpperCase()) { errMsg += "Email addresses do not match\n"; }
if(5 > 4)
if("Clinton" > "Bush")
if(5 == '5')
if(0 < x && x < 10)
if(!firstName)
if(nincompoops.length == 1)
if(isNaN(fruitcake))
var firstName = prompt('First Name?'); if(firstName.toUpperCase() === 'ESTELLE') { alert(firstName); }
var errMsg, email1 = prompt('Your email address:'); email2 = prompt('Re-enter email address:'); if (email1.toUpperCase() != email2.toUpperCase()) { errMsg += "Email addresses do not match\n"; }
var age = parseInt(prompt('Lie about your age?')); if(isNaN(age)) { // not a number!! var banana = 'frog' }
var errMsg, email1 = prompt('Your email address:'); email2 = prompt('Re-enter email address:'); if (email1.toUpperCase() != email2.toUpperCase()) { errMsg += "Email addresses do not match\n"; }
var msg, age = +prompt("how old are you?"); if(!age || isNaN(age)) { msg = "You're too old to tell us your age?"; } else if (age <= 18 || age >= 65) { msg = "Kudos to you for getting mad skillz"; } else if (age > 45) { msg = "You should have lied about your age."; } else if (age < 25) { msg = "You're too young to rent a car,\ but old enough to rock JS"; } else { msg = "There's nothing wrong with being average."; }
while (condition is true) { // do these things // alter the condition }
var counter = 0, iterations = 4; while (counter < iterations) { // do these things counter++; }
Declared in one line
for(var counter=0; counter < iterations; counter++) { // do these things }
var count = 7; do { console.log(count); count++; } while (count < 5);
Will execute code block at least once, even if condition is never met.