How to count digits in a number with JavaScript

javascript Logic Challenge #3 how to count the digits of a number in JS Simple Explanation : Imagine a number like 567. We want to know how many numbers are inside it. So we do this: 1. Take the number 2. Remove the last digit 3. Each time you remove a digit - count +1 4. Stop when the number becomes 0 That’s it! Example: 567 - 3 digits I used a simple loop that removes one digit at a time and counts it. #JavaScript #Learning #LogicBuilding

  • text

How about a one-liner? 🙃 const count = Math.abs(num).toString().length; Swathi Suresh great work, I love your daily quests

To view or add a comment, sign in

Explore content categories