0
0
Blockchain / Solidityprogramming~10 mins

If-else statements 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 transaction amount is greater than 1000.

Blockchain / Solidity
if (transaction.amount [1] 1000) {
    approveTransaction();
} else {
    rejectTransaction();
}
Drag options to blanks, or click blank then click option'
A>
B!=
C==
D<
Attempts:
3 left
💡 Hint
Common Mistakes
Using '<' instead of '>' will check the wrong condition.
Using '==' checks equality, not greater than.
2fill in blank
medium

Complete the code to set the status to 'approved' if the balance is sufficient.

Blockchain / Solidity
if (user.balance [1] transaction.amount) {
    status = 'approved';
} else {
    status = 'denied';
}
Drag options to blanks, or click blank then click option'
A>=
B==
C<
D!=
Attempts:
3 left
💡 Hint
Common Mistakes
Using '<' will approve when balance is less, which is wrong.
Using '==' only approves if balance is exactly equal.
3fill in blank
hard

Fix the error in the if-else condition to check if the sender is the owner.

Blockchain / Solidity
if (sender [1] owner) {
    execute();
} else {
    revert();
}
Drag options to blanks, or click blank then click option'
A=
B==
C===
D!=
Attempts:
3 left
💡 Hint
Common Mistakes
Using '=' causes assignment, not comparison.
Using '===' is invalid syntax in blockchain smart contract languages.
4fill in blank
hard

Fill both blanks to approve if the amount is less than 500 and the sender is verified.

Blockchain / Solidity
if (transaction.amount [1] 500 && sender.verified [2] true) {
    approve();
} else {
    deny();
}
Drag options to blanks, or click blank then click option'
A<
B==
C!=
D>
Attempts:
3 left
💡 Hint
Common Mistakes
Using '>' instead of '<' reverses the amount check.
Using '!=' for verification checks the wrong condition.
5fill in blank
hard

Fill all three blanks to reject if the balance is less than amount or sender is not verified.

Blockchain / Solidity
if (user.balance [1] transaction.amount || sender.verified [2] [3]) {
    reject();
} else {
    accept();
}
Drag options to blanks, or click blank then click option'
A<
B==
Cfalse
D!=
Attempts:
3 left
💡 Hint
Common Mistakes
Using '!=' instead of '==' reverses the verification logic.
Using 'true' instead of 'false' checks the wrong condition.