soliditysmartcontractsremix

not getting mapping button while working in Remix IDE (solidity)


I'm new to programming and currently learning Solidity. I'm writing a very simple contract. After deploying the contract, I don't find mapping button. I'm using Remix IDE.

// SPDX-License-Identifier: MIT

pragma solidity ^0.8.18;

contract AgeFinder{

    uint256 ageNumber;

    struct Person {
        uint256 age;
        string name;
    }

    Person[] public listOfPeople;

    mapping (string => uint256) nameToAge;

    function addData( uint256 _age, string memory _name) public {
        listOfPeople.push(Person(_age, _name));
        nameToAge[_name] = _age;
    }
}

the buttons for addData and listOfPeople is visible but not nameToAge(the mapping one). I want nameToAge button, so that after entering name, the age will be shown.


Solution

  • because the nameToAge has no public.

    you need to change mapping (string => uint256) nameToAge; to mapping (string => uint256) public nameToAge;