Quotes help make search much faster. Example: "Practice Makes Perfect"

Monday, December 3, 2012

Codecademy: Codeyear Ternary Operator Practice


//sample solution


var myAge = prompt("How old are you?")

/* a simple if else statement
if (myAge >= 18) {
 answer = "adult";
}
else {
 answer = "non-adult" ;
}*/

// rewrite the code above using a ternary operator
answer = myAge >= 18 ? "adult" : "non-adult";

No comments:

Post a Comment


This is an example of scrolling text using Javascript.

Popular Posts