neoG Camp 2023 waitlist is open

Need Help?

lessonSeven: Lets build an is your birthday lucky app

This guide needs to be used alongside the lesson video.

problem statement

  • Take user's complete birthday
  • And his/her lucky number.
  • Now, find out if the sum of digits of birthday is divisible by the lucky number.
  • Show the result to the user.
  • Here's the link to the actual problem statement.

how will we complete this? 🤔

We will be using HTML, CSS, and Vanilla Javascript to complete this assignment, but you can also complete this using REACT 😄

Our end goal is to complete this assignment and build our logic.

So let's START!!!

ex0: input date of birth and the lucky number to check


Input date of birth and the lucky number to check then console the values.


There are multiple ways to take user input for date like:

  • Using select and option elements for taking inputs for Date, Month and Year.
  • or by using the input element.

Use Input element for date and define its type.

  • Define two input elements one for date of birth and another for lucky number.
  • add type attributes to both as date and number
  • Create a button and trigger an event using querySelector and addEventListener on click of that button console the values.

Input element can be used in multiple ways based on its types.

// Expected Output:
"2021-05-12" 2


ex01: calculate the sum of digits of the date.


Notice the value you get from date input, we get that as a string with a special character i.e hyphen but we need to calculate the sum of digits which are basically numbers.

The challenge here is to remove any special character from the input value.


  • Use replaceAll to replace the special characters from the string.
  • Read about replaceAll and good to know other available methods which we can use for string manipulation.
  • Once you remove them sum up all the digits.
  • Use for loop for adding all the digits, use charAt to index each value. Make sure you typecast character to Number.
  • Read about typecasting here which datatypes can be typecasted from and to what type.
  • You can also sum the digits using while loop using modulus



Read about how to traverse index and values using in and of in for loop.

for(let value of date)
for(let index in date)

for...of - JavaScript | MDN - JavaScript | MDN

ex02: check if the birthday is lucky?


We have calculated the sum of digits and have taken user input for the lucky number to check. Now check whether the birthday is lucky or not.


  • Use modulus % operator to check whether the sum of digits is divisible by the input number or not.
  • If true display a message like your birthday is lucky else your birthday is NOT lucky, so sad using a textarea element.


Wasn't that simple? 😃

  • Customize your display message. Try to make it attractive and beautify it using CSS.
  • Add validations for input fields.


  • Create this as a website, and put a privacy notice. Say that you're not storing data.
  • Use the footer to redirect to your social media accounts and your portfolio.

**assignments for markEleven**

Tell your friends if their birthdates are lucky or not. Use this guide to build a "Is your birthday lucky" app in VanillaJS or React and this would be your markEleven project from the mark15 checklist.

stuck? need help?

If you have doubts anywhere during levelZero, we have a 21k+ strong developer community on Discord.

Go to Discord Server and ask doubts in the general-coding channel.