Challenge 9
tx.origin Misuse
LowArrays and loops
Challenge
Add numbers to an array and calculate their sum. Review the loop in the published sample.
Starter code
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
contract ArraySum {
uint[] public numbers;
function addNumber(uint _number) public {
numbers.push(_number);
}
function calculateSum() public view returns (uint) {
uint sum = 0;
// Complete the loop shown in the source challenge.
return sum;
}
}Show hint
Iterate over each element and add it to sum.