0
0
Blockchain / Solidityprogramming~10 mins

Using for directive 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 loop through each block in the blockchain.

Blockchain / Solidity
for block in [1] {
    // process block
}
Drag options to blanks, or click blank then click option'
Aledger
Bchain
Cblocks
Dblockchain
Attempts:
3 left
💡 Hint
Common Mistakes
Using a variable name that does not hold the blocks.
Forgetting to use the correct variable name.
2fill in blank
medium

Complete the code to print the hash of each block in the blockchain.

Blockchain / Solidity
for block in blockchain {
    print([1]);
}
Drag options to blanks, or click blank then click option'
Ablock.hash
Bblock.previousHash
Cblock.data
Dblock.index
Attempts:
3 left
💡 Hint
Common Mistakes
Printing the previous block's hash instead of the current block's hash.
Printing block data instead of the hash.
3fill in blank
hard

Fix the error in the for loop to correctly iterate over the blockchain array.

Blockchain / Solidity
for (let [1] = 0; [1] < blockchain.length; [1]++) {
    console.log(blockchain[[1]].hash);
}
Drag options to blanks, or click blank then click option'
Ai
Bblock
Cindex
Dcount
Attempts:
3 left
💡 Hint
Common Mistakes
Using a variable name that is not consistent throughout the loop.
Using a variable name that conflicts with block objects.
4fill in blank
hard

Fill both blanks to create a dictionary of block hashes and their data for blocks with index greater than 0.

Blockchain / Solidity
const blockData = {
  [1]: blockchain[[2]].data
  for [2] in blockchain if blockchain[[2]].index > 0
};
Drag options to blanks, or click blank then click option'
Ablockchain[blockIndex].hash
BblockIndex
Dblock
Attempts:
3 left
💡 Hint
Common Mistakes
Using the wrong variable name for the loop.
Not accessing blockchain elements by index.
5fill in blank
hard

Fill both blanks to filter blocks with data value greater than 100 and create a new list of their hashes.

Blockchain / Solidity
const filteredHashes = blockchain.filter(block => block.data [1] 100).map(block => block.[2]);
Drag options to blanks, or click blank then click option'
A>
Bhash
C<
Ddata
Attempts:
3 left
💡 Hint
Common Mistakes
Using the wrong comparison operator.
Mapping to the wrong property.