sadanandpai / frontend-mini-challenges

Collection of frontend challenges for learning and interviews
https://sadanandpai.github.io/frontend-mini-challenges/
MIT License
2.02k stars 494 forks source link

[React/table-colorizer]: No warning raised on entering an invalid number #336

Closed proghax333 closed 10 months ago

proghax333 commented 10 months ago

Framework/code-stack

React

Scope

Table Colorizer

Description

React Table Colorizer app does not warn/alert on entering an invalid number (0).

Expected behaviour

An alert should be created, showing the message: Enter a valid number.

Suggested Solutions

https://github.com/sadanandpai/frontend-mini-challenges/blob/f274042ee9e18f500017c6929cb789fdae4f777c/react/src/machine-coding/table-colorizer/TableColorizer.jsx#L14

Replace parseInt(colRef.current.value) < 0 with parseInt(colRef.current.value) < 1.

Additional Context

Already fixed it on my fork, waiting for approval to create a pull request.

arpansaha13 commented 10 months ago

You may show the text in red color below the input field instead of creating an alert. And yes you can open the PR for it. Also you may mention the valid range in your error message.