You are close to getting the ultimate power! Are you ready to command your robot using conditions? In JavaScript, conditions allow you to control what your robots do based on different situations.
This type of prompt engages you in active problem-solving by providing challenges or tasks that require applying concepts. This can work to compare your results with your peers!
if (robot.status === "active" && robot.battery > 50) {
console.log("Robot" + robot.name + "is active and has sufficient battery.");
}
//Output : Robot RoboGuard is active and has sufficient battery.
```
### OR Operator (||)
The OR operator groups conditions:
```js
if (robot.type === "security" || robot.type === "assistant") {
console.log(robot.name + "is available for tasks.");
}
```
### `else if` Keyword
Chain conditions using else if:
```js
if (temperature <8){
console.log("Very cold!");
} else if (temperature <16){
console.log("Still too cold...");
} else if (temperature <24){
console.log("Getting warmer");
} else if (temperature <32){
console.log("Nice :)");
} else {
console.log("Too hot!!!");
}
```
#### **`Prompt Example`**:
- "Give me an easy coding challenge involving conditions in JavaScript, and provide feedback on my solution."
### Instructions
#### Task 1:
Your Robot must always seek the truth.
- Check if the value of the provided variable `truth` is truthy, log '`The truth was spoken.`'
- Otherwise, log '`Lies !!!!`' because the value of the provided variable truth is falsy.
#### Task 2:
Your `RoboGuard's traveling company` has a special promotion for robot members aged between 18 and 25. Write the if condition that will check if the robot user can benefit from the promotion:
-`user.age` must be at least `18`.
-`user.age` must be less than or equal to `25`.
-`user.activeMembership` must be `true`.
If `all` of these conditions are `true`, log the message '`You can benefit from our special promotion`'.
> Hint : use AND Operator in your condition!
#### Task 3:
Your RoboGuard is selling plane tickets, each costing `9.99$`. The RoboGuard must confirm that the customer robot has the means to buy this ticket.
The customer robot may have enough cash `or` a voucher.
Check if the provided variable customer can afford the ticket:
If the customer has enough `cash` (`customer.cash` property)
`or` If the customer has a `voucher` (`customer.hasVoucher` property is true)
If so, `increment` the provided variable `ticketSold` value by `1`.