Welcome to this guide which will be a companion with the pair programming workshop. This guide needs to be used alongside the youtube class
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!!!
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 birth
and another for lucky number
.type
attributes to both as date
and number
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
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.
replaceAll
to replace the special characters from the string.replaceAll
and good to know other available methods which we can use for string manipulation.charAt
to index each value. Make sure you typecast character to Number
.modulus
Extra:
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)
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.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? 😃