Challenge - 5 Problems
If-else Mastery in Blockchain
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate2:00remaining
Output of a simple if-else in Solidity
What is the output of this Solidity function when
value = 10?Blockchain / Solidity
pragma solidity ^0.8.0; contract Test { function checkValue(uint value) public pure returns (string memory) { if (value > 10) { return "Greater"; } else if (value == 10) { return "Equal"; } else { return "Less"; } } }
Attempts:
2 left
💡 Hint
Check the condition that matches exactly 10.
✗ Incorrect
The function returns "Equal" because the value is exactly 10, matching the else if condition.
❓ Predict Output
intermediate2:00remaining
If-else behavior with boolean in smart contract
What will the function return when
flag = false?Blockchain / Solidity
pragma solidity ^0.8.0; contract FlagCheck { function checkFlag(bool flag) public pure returns (string memory) { if (flag) { return "True"; } else { return "False"; } } }
Attempts:
2 left
💡 Hint
Think about what happens when the flag is false.
✗ Incorrect
Since flag is false, the else branch runs and returns "False".
❓ Predict Output
advanced2:30remaining
Nested if-else output in Solidity
What does this function return when
score = 75?Blockchain / Solidity
pragma solidity ^0.8.0; contract ScoreCheck { function grade(uint score) public pure returns (string memory) { if (score >= 90) { return "A"; } else { if (score >= 80) { return "B"; } else { if (score >= 70) { return "C"; } else { return "F"; } } } } }
Attempts:
2 left
💡 Hint
Check each condition from top to bottom.
✗ Incorrect
75 is less than 80 but greater or equal to 70, so it returns "C".
🧠 Conceptual
advanced2:30remaining
Error type from missing else in Solidity if-else
What error will this Solidity code produce when compiled?
Blockchain / Solidity
pragma solidity ^0.8.0; contract Test { function check(uint x) public pure returns (string memory) { if (x > 5) return "High"; else return "Low"; } }
Attempts:
2 left
💡 Hint
Look at the placement of else after a return statement.
✗ Incorrect
The else is correctly placed after the if statement, so no syntax error occurs.
❓ Predict Output
expert3:00remaining
Output of complex if-else with multiple conditions
What is the output of this Solidity function when
value = 15?Blockchain / Solidity
pragma solidity ^0.8.0; contract Complex { function test(uint value) public pure returns (string memory) { if (value < 10) { return "Less than 10"; } else if (value < 20) { if (value % 2 == 0) { return "Even and less than 20"; } else { return "Odd and less than 20"; } } else { return "20 or more"; } } }
Attempts:
2 left
💡 Hint
Check if 15 is less than 20 and if it is even or odd.
✗ Incorrect
15 is less than 20 and odd, so it returns "Odd and less than 20".