<title>Calories Burned Calculator</title>
  </head>
  <body>
    <h1>Calories Burned Calculator</h1>
    <form>
      <label for="activity">Activity:</label>
      <select id="activity">
        <option value="0">--Select Activity--</option>
        <option value="running">Running</option>
        <option value="walking">Walking</option>
        <option value="biking">Biking</option>
        <option value="swimming">Swimming</option>
        <option value="MMA">MMA</option>
      </select>
      <br><br>
      <label for="time">Time (in minutes):</label>
      <input type="number" id="time" name="time">
      <br><br>
      <label for="weight">Weight (in pounds):</label>
      <input type="number" id="weight" name="weight">
      <br><br>
      <input type="button" value="Calculate" onclick="calculateCalories()">
      <br><br>
      <label for="result">Calories Burned:</label>
      <input type="text" id="result" name="result" readonly>
    </form>
    </body>
 body {
        font-family: Arial, sans-serif;
        background-color: #f4f4f4;
      }
      h1 {
        font-size: 36px;
        font-weight: bold;
        text-align: center;
        margin-top: 50px;
        margin-bottom: 30px;
      }
      form {
        width: 400px;
        margin: 0 auto;
        background-color: #fff;
        padding: 30px;
        border-radius: 5px;
        box-shadow: 0px 0px 5px rgba(0, 0, 0, 0.2);
      }
      label {
        display: block;
        font-size: 16px;
        font-weight: bold;
        margin-bottom: 10px;
      }
      select, input[type="number"], input[type="text"] {
        display: block;
        width: 100%;
        padding: 10px;
        margin-bottom: 20px;
        border: 2px solid #ccc;
        border-radius: 5px;
        font-size: 16px;
        font-weight: bold;
      }
      input[type="button"] {
        display: block;
        width: 100%;
        padding: 10px;
        margin-top: 20px;
        border: none;
        border-radius: 5px;
        background-color: #000;
        color: #fff;
        font-size: 16px;
        font-weight: bold;
        cursor: pointer;
      }
      input[type="button"]:hover {
        background-color: #222;
      }
      input[type="text"][readonly] {
        background-color: #f4f4f4;
        color: #000;
        cursor: not-allowed;
      }
 function calculateCalories() {
        // Get values from the form
        const activity = document.getElementById("activity").value;
        const time = document.getElementById("time").value;
        const weight = document.getElementById("weight").value;
        
        // Calculate calories burned based on activity and weight
        let calories = 0;
        switch (activity) {
          case "running":
            calories = 0.08 * weight * time;
            break;
          case "walking":
            calories = 0.02 * weight * time;
            break;
          case "biking":
            calories = 0.065 * weight * time;
            break;
          case "swimming":
            calories = 0.05 * weight * time;
            break;
            
  case "MMA":
            calories = 0.12 * weight * time;
            break;
          default:
            alert("Please select an activity.");
            return;
        }
        
        // Display result in the form
        document.getElementById("result").value = calories.toFixed(2) + " calories";
      }
Run Pen

External CSS

This Pen doesn't use any external CSS resources.

External JavaScript

This Pen doesn't use any external JavaScript resources.