Assignment Array and Loop

Published by Mario Oettler on

Last Updated on 23. March 2023 by Martin Schuster

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:

myArray.lenght;

Categories:

https://blockchain-academy.hs-mittweida.de/wp-content/uploads/2021/04/logo_bcam_rgb_gross.png

Welcome

Blockchain Academy

Continue with credential

No account yet?

Powered by Hidy

Register with Hidy


Register
Sign in

We need the following credential to register:

please select:

To create a new account, we need the following data from you:

We would appreciate the following additional information from you for the creation of your account:

Welcome

Blockchain Academy

Continue with credential

Already have an account?

Powered by Hidy

Sign in with Hidy


Register
Sign in

We need the following credential to log in:

please select: