Menu
Coddy logo textTech

Shared Counter

Part of the Fundamentals section of Coddy's Solidity journey. Lesson 30 of 53.

challenge icon

Challenge

Medium

Create state variable count, an internal helper add(n) that increases it, and an internal view helper readCount(). Set count to start, call add(first) then add(second), and print readCount().

The tests pass arguments to main in this order: uint256 start, uint256 first, uint256 second. Each test starts with fresh contract state.

Use console.log for the requested output. Print only the requested values, one per line, with no extra labels unless the task specifies them.

Try it yourself

// SPDX-License-Identifier: MIT
pragma solidity ^0.8.26;
import "forge-std/console.sol";
contract Main {
    function main(uint256 start, uint256 first, uint256 second) external  {
        // Write your solution here.
    }
}

All lessons in Fundamentals

Practice on your own: Solidity playground