DEV Community

gaganjot singh
gaganjot singh

Posted on • Edited on

Creating a Dog Age Calculator with ChatGPT


Table of Contents

  1. Introduction
  2. Why a Dog Age Calculator?
  3. How ChatGPT Helped
  4. Step 1: HTML Structure
  5. Step 2: CSS Styling
  6. Step 3: JavaScript Logic
  7. Is AI a Threat to Programmers?
  8. Related Tools
  9. Final Thoughts

Introduction

As a programmer, I enjoy experimenting with fun projects. Recently, I decided to create a Dog Age Calculator—a tool to convert human years into dog years. Instead of starting from scratch, I teamed up with ChatGPT to speed up the process.

ChatGPT acted as a powerful coding assistant, helping me build a functional base that I could customize and refine. In this post, I’ll show you how we created a Dog Age Calculator, complete with separate files for HTML, CSS, and JavaScript.


Why a Dog Age Calculator?

The concept of “dog years” fascinates many dog owners, who wonder how old their pets are in human terms. This project is:

  • Simple yet practical, with input validation and result display.
  • Beginner-friendly, perfect for honing your JavaScript skills.
  • Fun and relatable, especially for pet lovers.

Let’s get started!


How ChatGPT Helped

To save time, I asked ChatGPT:

"Write a Dog Age Calculator using HTML, CSS, and JavaScript."

ChatGPT generated a solid codebase in seconds, which I personalized to add my own style and improvements. Below is the final version of the project.


Check out this Pen I made!

Step 1: HTML Structure

The HTML provides the structure of the calculator.

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Dog Age Calculator</title>
    <link rel="stylesheet" href="styles.css">
</head>
<body>
    <div class="calculator-container">
        <h1>Dog Age Calculator</h1>
        <p>Enter your dog's age in human years:</p>
        <input type="number" id="humanYears" placeholder="Enter human years" min="0">
        <button onclick="calculateDogAge()">Calculate</button>
        <p class="result" id="result"></p>
    </div>
    <script src="script.js"></script>
</body>
</html>
Enter fullscreen mode Exit fullscreen mode

Step 2: CSS Styling

The CSS makes the calculator visually appealing.

/* styles.css */

/* Reset */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'Arial', sans-serif;
    background: linear-gradient(135deg, #ffafbd, #ffc3a0);
    color: #333;
    display: flex;
    align-items: center;
    justify-content: center;
    height: 100vh;
}

.calculator-container {
    background: #fff;
    padding: 20px 30px;
    border-radius: 10px;
    box-shadow: 0 8px 15px rgba(0, 0, 0, 0.2);
    text-align: center;
    width: 300px;
}

.calculator-container h1 {
    font-size: 24px;
    margin-bottom: 20px;
    color: #ff6f61;
}

.calculator-container input {
    width: 100%;
    padding: 10px;
    margin: 10px 0;
    border: 1px solid #ccc;
    border-radius: 5px;
    font-size: 16px;
}

.calculator-container button {
    background: #ff6f61;
    color: #fff;
    border: none;
    padding: 10px 15px;
    border-radius: 5px;
    font-size: 16px;
    cursor: pointer;
    transition: background 0.3s;
}

.calculator-container button:hover {
    background: #e55a4e;
}

.result {
    margin-top: 20px;
    font-size: 18px;
    color: #333;
    font-weight: bold;
}
Enter fullscreen mode Exit fullscreen mode

Step 3: JavaScript Logic

The JavaScript handles the calculator’s functionality.

// script.js

function calculateDogAge() {
    const humanYears = document.getElementById('humanYears').value;
    let dogYears;

    if (humanYears === "" || isNaN(humanYears) || humanYears <= 0) {
        dogYears = "Please enter a valid positive number!";
    } else if (humanYears <= 2) {
        dogYears = humanYears * 10.5;
    } else {
        dogYears = (2 * 10.5) + ((humanYears - 2) * 4);
    }

    document.getElementById('result').innerText = 
        typeof dogYears === "number"
        ? `Your dog's age in dog years is: ${dogYears.toFixed(1)}`
        : dogYears;
}
Enter fullscreen mode Exit fullscreen mode

Is AI a Threat to Programmers?

The Pros of AI for Programmers

  1. Speed and Efficiency: AI helps with repetitive tasks and boilerplate code, saving hours.
  2. Learning Aid: It’s a fantastic tool for beginners to learn programming concepts.
  3. Focus on Creativity: AI handles basic tasks, allowing developers to concentrate on solving complex problems.

The Challenges of AI for Programmers

  1. Over-Reliance: There’s a risk of becoming too dependent on AI, which could hinder learning.
  2. Job Concerns: Simple coding jobs may get automated, pushing programmers to specialize in advanced areas.
  3. Code Quality: AI-generated code isn’t always optimized or error-free. A skilled developer is still needed to review and improve it.

Bottom Line: AI won’t replace programmers anytime soon, but it’s essential to adapt and upskill. Think of AI as a tool, not a replacement. Stay curious, keep learning, and embrace innovation!


Related Tools

Explore other dog-related calculators:


Final Thoughts

This project highlights how tools like ChatGPT can complement a programmer’s workflow. It’s like having a coding buddy that handles the basics while you focus on creativity.

While AI is powerful, remember that it’s just a tool. Your unique problem-solving skills and creativity will always make you indispensable.

Happy coding, and don’t forget to give your dog an extra pat today! 🐶


Heroku

Deploy with ease. Manage efficiently. Scale faster.

Leave the infrastructure headaches to us, while you focus on pushing boundaries, realizing your vision, and making a lasting impression on your users.

Get Started

Top comments (0)

AWS Security LIVE!

Join us for AWS Security LIVE!

Discover the future of cloud security. Tune in live for trends, tips, and solutions from AWS and AWS Partners.

Learn More

👋 Kindness is contagious

If you found this article helpful, please give a ❤️ or share a friendly comment!

Got it