Day3: Let's write a simple application that converts words to into minutes by calculating an estimated time required to read manually.

Let's write a simple application that converts words into minutes by calculating an estimated time required to read manually.

The algorithm is as follows:

  1. First, find the word count. Let's say it's 936 words.
  2. Divide your total word count by 200. You'll get a decimal number, in this case, 4.69.
  3. The first part of your decimal number is your minute. In this case, it is 4.
  4. Take the second part of your decimal, the points which is 0.69, multiply that by 0.60. Those are your seconds. Round them up or down as necessary to get a whole second. In this case, 0.69*0.60 = 0.414. We will round that up to 41 seconds. The result? 938 words = a 4 minute, 41-second read. But that’s really specific. Why not round that time to make things simpler for your reader? Anything less than 30 seconds gets ignored; anything more than 30 seconds gets rounded up to the next minute. Ta-da! That rounding makes your 938-word article a 5-minute read.

15 Days of Code 6/26/2020 Unifiedcamp 2 Answer(s) 277 views


Unifiedcamp

Author

Unifiedcamp 23

Leave a reply

Post your answer

Answers ( 2 )

  1. User
    140
    6/26/2020
    View

    Calculating an estimated time to read a post in PHP.

    <?php
        
    if (isset($_POST['submit']) && $_POST['post'] != "") {
        $post = $_POST['post'];
        $wordCount = str_word_count(strip_tags($post));
        $readingTime = ceil($wordCount / 200);
    
        if ($readingTime == 1) {
            $min = " minute";
        }else{
            $min = " minutes";
        }
        $timer = $readingTime . $min;
    
    }else{
        "<script>alert('Please make a post');</script>";
    }
    ?>
    <!DOCTYPE html>
    <html>
    <head>
        <title>Reading Time</title>
    </head>
    <body>
        <form action="" method="post">
            <input type="text" name="post">
            <br>
            <input type="submit" name="submit" value="Submit">
        </form>
        <?php echo $timer;?>
    </body>
    </html>
    

    Calculating an estimated time to read a post using JavaScript.

    <!DOCTYPE html>
    <html>
    <head>
        <title>Reading Time</title>
    </head>
    <body>
        <div>
            <p>Your Post</p>
        </div>
        <div>
            <textarea onkeyup="calcRT(this)" placeholder="Write your post..."></textarea>
        </div>
        
        <div>
           <p id="readingTime">0 min read</p>
        </div>
    
        <script type="text/javascript">
            window.calcRT = ev => {
                  let time;
          
                  let postLength = ev.value.split(" ").length;
                  if(postLength > 0){
                    let value = Math.ceil(postLength / 200);
                    result = `~${value} minute(s) read`;
                  }
                document.getElementById("readingTime").innerText = time;
            };
        </script>
    </body>
    </html>
    

  2. User
    49
    7/14/2020
    View

    # A python program that calculates the time it takes to
    #read words entered by the user
    words = input("Write here: ")
    count = 0

    #count the number of words
    for word in words:
        count += 1


    div = float(f"{(count / 200):,.2f}")
    minutes = int(div)
    sec = int(((div - minutes) * .60) * 100)#calculates for the seconds

    if sec <= 30:
        print(f"Thats a {minutes} minute(s) read")
        
    elif sec > 30:
            minutes += 1
            print(f"That's a {minutes} minute(s) read.")

    else:
        print("Enter a valid input")