91 lines
1.7 KiB
JavaScript
91 lines
1.7 KiB
JavaScript
/*
|
|
|
|
Operators
|
|
---------
|
|
|
|
CoffeScript JavaScript
|
|
== is ===
|
|
!= isnt !==
|
|
not !
|
|
and &&
|
|
or ||
|
|
true yes on true
|
|
false no off false
|
|
|
|
*/
|
|
var Decaf, addCaffeine, base, base1, base2, coffee, cupsOfCoffee, level, message, paid, pour;
|
|
|
|
paid = coffee = pour = function() {};
|
|
|
|
if (paid() && coffee() === true) {
|
|
pour();
|
|
}
|
|
|
|
addCaffeine = Decaf = function() {};
|
|
|
|
if (!Decaf()) {
|
|
addCaffeine();
|
|
}
|
|
|
|
if (!Decaf()) {
|
|
addCaffeine();
|
|
}
|
|
|
|
// Combined range checks
|
|
level = 4;
|
|
|
|
if ((2 < level && level < 5)) {
|
|
alert("In range");
|
|
}
|
|
|
|
// Functional switch.
|
|
message = (function() {
|
|
switch (cupsOfCoffee) {
|
|
case 0:
|
|
return 'Asleep';
|
|
case 1:
|
|
return 'Eyes open';
|
|
case 2:
|
|
return 'Buzzed';
|
|
default:
|
|
return 'Dangerous';
|
|
}
|
|
})();
|
|
|
|
// Existential check: not undefined and not null.
|
|
if (typeof cupsOfCoffee !== "undefined" && cupsOfCoffee !== null) {
|
|
alert('Exists');
|
|
}
|
|
|
|
if (typeof cupsOfCoffee !== "undefined" && cupsOfCoffee !== null) {
|
|
alert('Exists');
|
|
}
|
|
|
|
// Not strictly identical to the two shorter forms below.
|
|
if (typeof cupsOfCoffee === "undefined" || cupsOfCoffee === null) {
|
|
cupsOfCoffee = 0;
|
|
}
|
|
|
|
if (cupsOfCoffee == null) {
|
|
cupsOfCoffee = 0;
|
|
}
|
|
|
|
if (cupsOfCoffee == null) {
|
|
cupsOfCoffee = 0;
|
|
}
|
|
|
|
if (typeof coffeePot !== "undefined" && coffeePot !== null) {
|
|
coffeePot.brew();
|
|
}
|
|
|
|
if (typeof vehicle.start_engine === "function") {
|
|
if (typeof (base = vehicle.start_engine()).shift_gear === "function") {
|
|
if (typeof (base1 = base.shift_gear()).crank === "function") {
|
|
if (typeof (base2 = base1.crank()).press_gas === "function") {
|
|
base2.press_gas();
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
//# sourceMappingURL=3-2-operators.js.map
|