0
pragma solidity >= 0.7.0 < 0.9.0;
contract Learningloop {
    
    uint [] public numberslist = [1,2,3,4,5,6,7,8,9,10]; 
    
    function getCount(uint _number) public view returns(uint){
        uint Rcount = 0; 
        //3 part statement for a loop;
        //1. initilize the start of the loop; 
        //2. determine the lenght of the loop; 
        //3. to direct the index after each turn; 
       for(uint i=1; i < numberslist.lenght; i++) {
           if (CheckModIsZero(numberslist[i], _number)){
             Rcount ++;   
           }
       }
       return Rcount;  
    }
    
    function CheckModIsZero( uint _num, uint _nums) public view returns (bool){
       if (_num % _nums == 0) {
           return true; 
       } else {
           return false; 
       }
    }
}

Please, what am I doing wrong? The error is coming from this line of code:

for(uint i=1; i < numberslist.lenght; i++) {

1 Answer 1

1

It is a typo in your code: numberslist.length

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.