Calculation sheet

Your task is to implement a minimal calculation sheet that supports basic math operations and allows you to create formulas that reference other cells.

Requirements:

  • Display a fixed grid: 3 columns (A, B, C) and 7 rows (1-7).
  • Clicking on the cell should show an input in that cell. The input should be focused automatically.
  • It should be possible to enter any text in the input or enter a formula.
  • Pressing the 'Enter' key or blurring the input (e.g., focusing on other cells or clicking anywhere on the page), should display the entered value or calculate the formula.
  • A formula starts with a = character.
  • A formula should support basic operations +, -, *, /, and parenthesis (, ).
    Example formulas:
    • =1
    • =1+2
    • =-1+2
    • =2*3/3+1
    • =((1+1) * 2)
  • There can be spaces in the formula.
  • It should be possible to reference other cells in the formula by entering cell coordinates.
    Example formulas:
    • =A1+A2
    • =B1*2
    • =(1+3)*B1 + C2
  • Display #ERR if the formula can't be evaluated.
    A formula can't be evaluated if:
    • There is a division by 0: =10/0.
    • The referenced cell is empty or contains an invalid value: =A1+3, where A1 is not a number.
    • There is an infinite cycle between cells: A1 references B1, B1references C1, C1 references A1.
  • No need to support fractions.

You are free to add classes, styles, ids, but don't edit or remove data-test attributes.
Create an account to start coding
Create account