0
0
Blockchain / Solidityprogramming~10 mins

Short-circuiting in conditions in Blockchain / Solidity - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to check if the balance is positive before sending funds.

Blockchain / Solidity
if (balance [1] 0) {
    sendFunds();
}
Drag options to blanks, or click blank then click option'
A<
B!=
C>
D==
Attempts:
3 left
💡 Hint
Common Mistakes
Using equality operator instead of greater than
Checking if balance is less than zero
2fill in blank
medium

Complete the code to short-circuit and avoid division by zero.

Blockchain / Solidity
if (denominator != 0 && numerator [1] denominator) {
    processResult();
}
Drag options to blanks, or click blank then click option'
A==
B>
C<
D!=
Attempts:
3 left
💡 Hint
Common Mistakes
Using greater than or less than instead of equality
Not checking denominator first
3fill in blank
hard

Fix the error in the condition to short-circuit correctly when checking user authorization.

Blockchain / Solidity
if (isAdmin() [1] isOwner()) {
    grantAccess();
}
Drag options to blanks, or click blank then click option'
A&
B||
C&&
D|
Attempts:
3 left
💡 Hint
Common Mistakes
Using logical AND instead of OR
Using bitwise operators
4fill in blank
hard

Fill both blanks to create a short-circuit condition that checks if the contract is active and the caller is authorized.

Blockchain / Solidity
if (contract[1]active && caller[2]authorized) {
    executeTransaction();
}
Drag options to blanks, or click blank then click option'
A.
B==
C!=
D&&
Attempts:
3 left
💡 Hint
Common Mistakes
Using comparison operators instead of dot
Using logical operators inside property access
5fill in blank
hard

Fill all three blanks to create a short-circuit condition that checks if the user is verified, has enough tokens, and the transaction amount is positive.

Blockchain / Solidity
if (user[1]verified && tokens [2] amount && amount [3] 0) {
    processPayment();
}
Drag options to blanks, or click blank then click option'
A.
B>=
C>
D==
Attempts:
3 left
💡 Hint
Common Mistakes
Using equality instead of comparison
Using dot operator incorrectly