Menu
Coddy logo textTech

Multiplication

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

The * operator multiplies values. Multiplication happens before addition and subtraction unless parentheses specify a different grouping. Parentheses are useful when the intended order should be obvious to a reader.

The statements in this excerpt run inside the provided main function.

uint256 packs = 6;
uint256 each = 4;
console.log(packs * each + 3);

Six groups of four make twenty-four, and three additional items make twenty-seven. The expression (packs + 3) * each would describe a different problem: three additional packs, rather than three additional items.

Multiplication happens before addition unless parentheses change the grouping.

challenge icon

Challenge

Easy

A rack has rows rows with perRow spaces each. Print its total number of spaces.

The tests pass arguments to main in this order: uint256 rows, uint256 perRow. 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 rows, uint256 perRow) external view {
        // Write your solution here.
    }
}
quiz iconTest yourself

This lesson includes a short quiz. Start the lesson to answer it and track your progress.

All lessons in Fundamentals

Practice on your own: Solidity playground