Coding Challenge Day-10

Valid Number

Screenshot (220).png

One last challenge! It's been a long one in a way.

Today's challenge was centred around writing a logic that returns true when a number is valid and false when it's not valid. The question gave some basic rules a valid number should follow, so that will be put into consideration as the logic is been written

Thought process

Looking at the question, It was a bit straightforward.

These were my thoughts:

  1. use the trim() method to clear the string of whitespaces.

  2. Convert the given string to a number.

  3. Check if the result from the conversion gave NaN or not.

  4. Return false from the function if the conversion gave NaN and true if it doesn't.

Implementation

I implemented exactly the way my thought process was and guess what? It was a wrong answer. For some reason the text Infinity was passing the test and returning true. To battle this I created a condition that checks if the input includes Infinity and then return false. Might not be the best solution but that gave me a pass for now.

What I learnt

Today's task was more of understanding the question better and interpreting it in the best possible way. Was also able to revise some basic JavaScript methods

Conclusion

Screenshot (221).png

I'm excited that I was able to stay on this challenge this long and finish. This is a big thing for me and I want to thank I4G for this opportunity to participate in this challenge

Thanks to those that were with me and read my articles from the start of the challenge till now.

Thank you for reading through

Challenge done!

You can follow me on Twitter

1
Subscribe to my newsletter

Read articles from Ameh Elijah Uma-Ojo directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

Ameh Elijah Uma-Ojo
Ameh Elijah Uma-Ojo

I'm a talented frontend developer with expertise in JavaScript, React, Tailwind, Firebase and a lot of other technologies. With a passion for creating intuitive user interfaces and seamless user experiences, I specialize in building modern web applications that are both beautiful and functional. In addition to my development skills, I'm also interested in technical writing. I enjoy sharing their knowledge with others and have a talent for explaining complex technical concepts in a clear and concise manner. When not coding or writing, I enjoy keeping up with the latest trends and advancements in technology. I'm always looking for new and innovative ways to improve my skills and stay on the cutting edge of the industry. Overall, I'm a versatile and driven professional with a bright future in both frontend development and technical writing.