Lucky Number
React.js
medium
25 mins
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
Preview what you need to build
Solve Similar questions π₯
Want to upskill? Explore our courses!
Namaste DSA
Master DSA from scratch with numerous problems, and expert guidance.
Namaste React
Wanna dive deep into React and become Frontend Expert? Learn with me now!
Namaste Frontend System Design
The most comprehensive and detailed course for frontend system design.
Namaste Node.js
Wanna dive deep into Node.js? Enroll into `Namaste Node.js` now!
