Welcome to this guide which will be a companion with the pair programming workshop. This guide needs to be used alongside the youtube class
Our end goal is to complete this assignment and build our logic.
So let's START!!!
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:
Use Input element for date and define its type.
date of birthand another for
typeattributes to both as
addEventListeneron 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
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.
replaceAllto replace the special characters from the string.
replaceAlland good to know other available methods which we can use for string manipulation.
charAtto index each value. Make sure you typecast character to
Read about how to traverse index and values using
of in for loop.
for(let value of date) for(let index in date)
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.
modulus% operator to check whether the sum of digits is divisible by the input number or not.
truedisplay a message like
your birthday is luckyelse
your birthday is NOT lucky, so sadusing a
Wasn't that simple? 😃