More complex decisions sometimes require two things to be true. The && operator allows you to check if both operand expressions are true, and then possibly perform some specific action using an if, if-else, or while block.
// Truth table for the boolean AND operator. console.log(true && true); console.log(true && false); console.log(false && true); console.log(false && false); |
Found a bug in the documentation? Let us know at documentation@code.org
Determines if it is currently working hours.
// Determines if it is currently working hours. var now = new Date(); var hours = now.getHours(); var workHours = false; if (hours >= 9 && hours < 17) { workHours = true; } console.log(workHours);
Check whether a given temperature is in a healthy range or not.
// Check for temperature in a good range or not. textLabel("tempLabelID", "What is your temperature?"); textInput("tempID", ""); button("buttonID", "Submit"); textLabel("tempMessageID", ""); onEvent("buttonID", "click", function(event) { setText("tempMessageID",""); var temp = getText("tempID"); if (temp >= 98 && temp <= 99.5) { setText("tempMessageID", "Your temperature is fine."); } else { setText("tempMessageID", "You may be sick."); } });
__ && __
Name | Type | Required? | Description |
---|---|---|---|
expression1 | boolean | The first boolean expression to evaluate. | |
expression2 | boolean | The second boolean expression to evaluate. |
Boolean (true or false)
Found a bug in the documentation? Let us know at documentation@code.org