Weekly Dev Challenge: Convert your age to DOG years.

Bishnu Prasad Chowdhury
3 min readFeb 21, 2021

This week’s SCRIMBA’s weekly dev challenge was Converting users age to dog years. So it was pretty simple and easy. I went ahead and declared the variables at the top which would interact with the DOM elements.

The UI had 1 text box and 2 buttons so added addEventListener to both the buttons on click and invoked the function to compute the logic of the calculation. To display two styles of coding for event listener, i added one function call in one btn event listener and on the other one i added the function itself within the declaration.

In the main logic i used type checking for negative or empty inputs and handled them appropriately.

In the main logic i added the calculation and then disabled the button and removed the event listener from the button.

Now removeEventListener second argument is a function so made a fake function returning null.

Overall the application looked like below and the output looked ok.

Used h1 tag as a manual error handling.

Showed the result once convert button is clicked and disabled the button.

On clicking the reset button it would acitvate the convert button again.

The code can be seen from the below link:

Please let me know with your comments if you would like to improve the code or any suggestion for the used code to refactor it.

Thanks for reading. Peace.

--

--

Bishnu Prasad Chowdhury

I love to learn about new technologies and new thing now and then. I get bored with thing very easily so i tend to move from one technology to another.