The moisture variable is 30, which is less than 40, so the if condition is true.
Step 2: Determine the returned string
Since condition is true, the function returns 'Water plants'.
Final Answer:
Water plants -> Option A
Quick Check:
moisture 30 < 40 = 'Water plants' [OK]
Hint: Check if condition true or false to find output [OK]
Common Mistakes:
Confusing return value with variable value
Ignoring the if condition logic
Assuming function returns moisture number
4. A LoRaWAN smart city sensor code snippet is not sending data as expected:
function sendData() {
let pollution = 55;
if pollution > 50 {
return 'Alert: High pollution';
} else {
return 'Pollution normal';
}
}
console.log(sendData());
What is the error in this code?
medium
A. Incorrect return statement syntax
B. Using let instead of const for pollution
C. Missing parentheses around the if condition
D. Missing semicolon after return statements
Solution
Step 1: Check syntax of the if statement
The if condition must have parentheses around the condition: if (pollution > 50) {...}
Step 2: Verify other syntax elements
Using let is allowed, return statements are correct, semicolons are optional in JavaScript.
Final Answer:
Missing parentheses around the if condition -> Option C
Quick Check:
if condition needs parentheses [OK]
Hint: Always put parentheses around if conditions [OK]
Common Mistakes:
Ignoring missing parentheses in if
Thinking let causes error here
Focusing on semicolons instead of condition syntax
5. A farmer wants to use LoRaWAN sensors to automate watering only when soil moisture is below 35% and temperature is above 20°C. Which logic best fits this use case?
hard
A. Trigger watering if moisture < 35 OR temperature > 20
B. Trigger watering if moisture < 35 AND temperature > 20
C. Trigger watering if moisture > 35 AND temperature < 20
D. Trigger watering if moisture > 35 OR temperature < 20
Solution
Step 1: Understand the condition requirements
Watering should happen only when both moisture is low (<35) and temperature is high (>20).
Step 2: Choose correct logical operator
AND operator ensures both conditions must be true to trigger watering.
Final Answer:
Trigger watering if moisture < 35 AND temperature > 20 -> Option B
Quick Check:
Both conditions true = AND operator [OK]
Hint: Use AND to require both conditions true [OK]
Common Mistakes:
Using OR which triggers watering too often
Reversing comparison signs
Ignoring temperature condition
Recommended
Ready to prove it?
Pass the test and this pattern moves unknownstrongwhile earning +1 Grip toward your certificate.