Assignment Array and Loop

Published by Mario Oettler on

Write a smart contract that declares a fixed size array (size = 8, data type uint256). Assign values to this array.

Implement a function that sums up all values until a certain index provided by the user. Return this value.

Check that the index provided by the user does not exceed the size (or length) of the array. Implement this check with:

  1. an if else statement: If the index is too high, the function should return 0
  2. a require statement: If the index is too high, provide an error message

The length of an array can be retrieved with: