Challenge - 5 Problems
For Directive Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate2:00remaining
Output of a simple for directive loop
What is the output of this blockchain smart contract snippet using a for directive to iterate over transactions?
Blockchain / Solidity
let total = 0; for (let i = 0; i < 3; i++) { total += i * 10; } console.log(total);
Attempts:
2 left
💡 Hint
Remember the loop runs from 0 to 2, adding i*10 each time.
✗ Incorrect
The loop runs with i = 0, 1, 2. The sums are 0*10 + 1*10 + 2*10 = 0 + 10 + 20 = 30.
🧠 Conceptual
intermediate1:30remaining
Understanding for directive in blockchain event processing
In a blockchain smart contract, which best describes the purpose of a for directive when processing a list of events?
Attempts:
2 left
💡 Hint
Think about how loops help handle multiple items.
✗ Incorrect
A for directive repeats code for each item in a list, allowing sequential processing of all events.
🔧 Debug
advanced2:00remaining
Identify the error in this for directive code
What error does this blockchain smart contract code produce?
Blockchain / Solidity
for (let i = 0; i < 5; i++) { console.log(i); }
Attempts:
2 left
💡 Hint
Check the syntax of the for loop header.
✗ Incorrect
The for loop syntax requires parentheses around the initialization, condition, and increment parts.
❓ Predict Output
advanced2:30remaining
Output of nested for directives in blockchain code
What is the output of this nested for directive code snippet?
Blockchain / Solidity
let result = ''; for (let i = 1; i <= 2; i++) { for (let j = 1; j <= 2; j++) { result += `${i}${j} `; } } console.log(result.trim());
Attempts:
2 left
💡 Hint
The outer loop controls the first digit, inner loop the second.
✗ Incorrect
The outer loop runs i=1,2; inner loop runs j=1,2; concatenating pairs in order: 11 12 21 22.
🚀 Application
expert3:00remaining
Calculating total token transfers using for directive
Given this blockchain code snippet that sums token transfers, what is the final value of totalTokens?
Blockchain / Solidity
const transfers = [100, 200, 50, 150]; let totalTokens = 0; for (const amount of transfers) { if (amount > 100) { totalTokens += amount; } } console.log(totalTokens);
Attempts:
2 left
💡 Hint
Add only amounts greater than 100.
✗ Incorrect
Only 200 and 150 are greater than 100, so totalTokens = 200 + 150 = 350.