Build a small React component that takes a number as input and determines if it is a Lucky Number.
A number is Lucky if the sum of its digits is a prime number. Lucky numbers are often used in games, fun quizzes, or small number-based challenges.
Things to do
- Create an input where the user can type a number.
- Implement a function to check if a number is prime.
- Implement a function to check if the sum of the digits of the number is prime.
- Display the result below the input:
- "Lucky Number" if the sum is prime.
- "Not a Lucky Number" if the sum is not prime.
- Empty string if the input is blank.
ClassNames
- Use this classnames in your code
- Input -> input-box
- Result -> result
Examples
input: "23"
output: "Lucky Number"
// 2 + 3 = 5 → prime
input: "222"
output: "Not a Lucky Number"
// 2 + 2 + 2 = 6 → not prime
input: ""
output: ""
// Empty input
Testing Instructions
- Please use the following data-testid attributes in your React component:
- input-box → for the input field
- result → for displaying the lucky number result